terom@26: """
terom@26: Helper functions for use in templates
terom@26: """
terom@26:
terom@47: import time, cgi
terom@26:
terom@46: from qmsk.web import config
terom@26:
terom@50: class Helpers (object) :
terom@26: """
terom@50: A bunch of useful helper methods for use in templates
terom@42: """
terom@42:
terom@50: def _bind_ctx (self, ctx) :
terom@50: """
terom@50: Initialize with the given render context
terom@50: """
terom@28:
terom@50: self.ctx = ctx
terom@28:
terom@50: def now (self) :
terom@50: """
terom@50: Returns the current date/time
terom@50: """
terom@47:
terom@50: return time.strftime(config.DATETIME_FMT)
terom@47:
terom@50: def copyright_year (self) :
terom@50: """
terom@50: Returns the current year
terom@50: """
terom@50:
terom@50: return time.strftime("%Y")
terom@50:
terom@50: def validation_notice (self, site_host) :
terom@50: """
terom@50: Returns a short "Validated XHTML & CSS" link text for the given site hostname
terom@50: """
terom@50:
terom@50: return 'Validated XHTML 1.0 Strict & CSS 2.1' % dict(
terom@50: host = site_host
terom@50: )
terom@50:
terom@50: def breadcrumb (self, trail, links=True) :
terom@50: """
terom@50: Returns a nicely formatted breadcrumb tail, optinally with links
terom@50: """
terom@50:
terom@50: return ' » '.join(
terom@50: (
terom@50: '%s' % (page.url, page.title) if links else page.title
terom@50: ) for page in trail
terom@50: )
terom@50:
terom@50: def escape (self, data) :
terom@50: """
terom@50: Escape data as HTML
terom@50: """
terom@50:
terom@50: return cgi.escape(data)
terom@50: