degal/templates.py
changeset 135 6534c77de93f
parent 127 37d19805b7ca
child 136 29e41a6415d7
equal deleted inserted replaced
134:ea05fe81ff67 135:6534c77de93f
     3 """
     3 """
     4 
     4 
     5 import html, version
     5 import html, version
     6 from html import tags
     6 from html import tags
     7 
     7 
       
     8 import urllib
       
     9 
       
    10 def quote_path (path) :
       
    11     """
       
    12         Return an unicode-safe string with the escaped contents of the given str-able object, suitable for use
       
    13         in HTTP URLs.
       
    14 
       
    15         This should provide correct behaviour for use with filesystem Nodes.
       
    16 
       
    17         XXX: even this could be abstracted to some kind of "URL" thing
       
    18     """
       
    19 
       
    20     return urllib.quote(str(path))
       
    21 
     8 def link_from (source, target) :
    22 def link_from (source, target) :
     9     """
    23     """
    10         Returns a partial a tag linking from the given page to the given page
    24         Returns a partial a tag linking from the given source page to the target page, escaping binary paths.
    11 
    25     """
    12         XXX: URLEncode unicode -> str!
    26 
    13     """
    27     return tags.a(href=quote_path(source.path_to(target)))
    14 
       
    15     return tags.a(href=source.path_to(target))
       
    16 
    28 
    17 def image_link (from_page, image, target) :
    29 def image_link (from_page, image, target) :
    18     """
    30     """
    19         Link to the given image
    31         Link to the given image
    20     """
    32     """
    21 
    33 
    22     return link_from(from_page, target)(
    34     return link_from(from_page, target)(
    23         tags.img(src=image.path_from(from_page))
    35         tags.img(src=quote_path(image.path_from(from_page)))
    24     )
    36     )
    25 
    37 
    26 def image_page (image) :
    38 def image_page (image) :
    27     """
    39     """
    28         The per-image view
    40         The per-image view