helpers.py
changeset 50 e4fbf480fbee
parent 47 99c45fc13edc
equal deleted inserted replaced
49:9b097385b463 50:e4fbf480fbee
     4 
     4 
     5 import time, cgi
     5 import time, cgi
     6 
     6 
     7 from qmsk.web import config
     7 from qmsk.web import config
     8 
     8 
     9 def now () :
     9 class Helpers (object) :
    10     """
    10     """
    11         Returns the current date/time
    11         A bunch of useful helper methods for use in templates
    12     """
    12     """
    13 
    13 
    14     return time.strftime(config.DATETIME_FMT)
    14     def _bind_ctx (self, ctx) :
       
    15         """
       
    16             Initialize with the given render context
       
    17         """
    15 
    18 
    16 def copyright_year () :
    19         self.ctx = ctx
    17     """
       
    18         Returns the current year
       
    19     """
       
    20 
    20 
    21     return time.strftime("%Y")
    21     def now (self) :
       
    22         """
       
    23             Returns the current date/time
       
    24         """
    22 
    25 
    23 def validation_notice (site_host) :
    26         return time.strftime(config.DATETIME_FMT)
    24     """
       
    25         Returns a short "Validated XHTML & CSS" link text for the given site hostname
       
    26     """
       
    27 
    27 
    28     return 'Validated <a href="http://validator.w3.org/check?uri=http://%(host)s">XHTML 1.0 Strict</a> &amp; <a href="http://jigsaw.w3.org/css-validator/validator?uri=http://%(host)s">CSS 2.1</a>' % dict(
    28     def copyright_year (self) :
    29         host = site_host
    29         """
    30     )
    30             Returns the current year
       
    31         """
    31 
    32 
    32 def breadcrumb (trail, links=True) :
    33         return time.strftime("%Y")
    33     """
       
    34         Returns a nicely formatted breadcrumb tail, optinally with links
       
    35     """
       
    36 
    34 
    37     return ' &raquo; '.join(
    35     def validation_notice (self, site_host) :
    38         (
    36         """
    39             '<a href="$site_url/%s">%s</a>' % (page.url, page.title) if links else page.title
    37             Returns a short "Validated XHTML & CSS" link text for the given site hostname
    40         ) for page in trail
    38         """
    41     )
       
    42 
    39 
    43 def escape (data) :
    40         return 'Validated <a href="http://validator.w3.org/check?uri=http://%(host)s">XHTML 1.0 Strict</a> &amp; <a href="http://jigsaw.w3.org/css-validator/validator?uri=http://%(host)s">CSS 2.1</a>' % dict(
    44     """
    41             host = site_host
    45         Escape data as HTML
    42         )
    46     """
       
    47 
    43 
    48     return cgi.escape(data)
    44     def breadcrumb (self, trail, links=True) :
       
    45         """
       
    46             Returns a nicely formatted breadcrumb tail, optinally with links
       
    47         """
    49 
    48 
       
    49         return ' &raquo; '.join(
       
    50             (
       
    51                 '<a href="$site_url/%s">%s</a>' % (page.url, page.title) if links else page.title
       
    52             ) for page in trail
       
    53         )
       
    54 
       
    55     def escape (self, data) :
       
    56         """
       
    57             Escape data as HTML
       
    58         """
       
    59 
       
    60         return cgi.escape(data)
       
    61