template.py
author Tero Marttila <terom@fixme.fi>
Mon, 16 Feb 2009 01:10:21 +0200
changeset 70 add1c1f7831c
parent 50 e4fbf480fbee
child 71 0162c2b21dc5
permissions -rw-r--r--
make TemplateError a normal Exception, not a http.ResponseError
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
"""
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
    Template handler
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
"""
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
     5
from mako import exceptions, util
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
     6
from mako.runtime import Context
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
from mako.template import Template
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     8
import mako.lookup
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
46
54c5f5f340de reduce to qmsk.web lib
Tero Marttila <terom@fixme.fi>
parents: 42
diff changeset
    10
from qmsk.web import http, helpers
26
9d3beac1b196 remove foo.html page, and rice up the footer a bit
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    11
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
# path to template files
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
TEMPLATE_DIR = "templates"
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
# path to cached templates
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
CACHE_DIR = "cache/templates"
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
# template file extension
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
TEMPLATE_EXT = "tmpl"
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
70
add1c1f7831c make TemplateError a normal Exception, not a http.ResponseError
Tero Marttila <terom@fixme.fi>
parents: 50
diff changeset
    21
class TemplateError (Exception) :
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
    """
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
        Raised by the template module functions
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
    """
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
    pass
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    28
class TemplateLoader (mako.lookup.TemplateLookup) :
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
    """
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    30
        Our own specialization of mako's TemplateLookup
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
    """
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    33
    def __init__ (self, path, fileext=TEMPLATE_EXT, _helper_class=helpers.Helpers, **env) :
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    34
        """
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    35
            Initialize to load templates located at path, with the given file extension.
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    36
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    37
            The given Helpers class is used to provide the helper methods
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    38
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    39
            The given **env list is supplied to every template render
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    40
        """
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    42
        # store
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    43
        self.path = path
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    44
        self.fileext = fileext
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    45
        self.helper_class = _helper_class
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    46
        self.env = env
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    47
            
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    48
        # build the TemplateLookup
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    49
        super(TemplateLoader, self).__init__(directories=[path], module_directory=CACHE_DIR)
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    50
    
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    51
    def _render (self, tpl, env, params) :
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    52
        """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    53
            Render the given template with given env/params, returning the output as a unicode string, or raising a TemplateError
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    54
        """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    55
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    56
        # build our Helpers class
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    57
        helpers = self.helper_class()
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    58
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    59
        # build the context from our env, and params
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    60
        ctx = dict(
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    61
            h       = helpers,
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    62
        )
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    63
        ctx.update(env)
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    64
        ctx.update(params)
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    65
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    66
        # the buffer to use for unicode output
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    67
        buf = util.FastEncodingBuffer(unicode=True)
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    68
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    69
        # the context to use
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    70
        context = Context(buf, **ctx)
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    71
        
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    72
        # bind our helper
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    73
        helpers._bind_ctx(context)
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    74
        
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    75
        try :
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    76
            # render template
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    77
            tpl.render_context(context)
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    78
        
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    79
        # a template may render other templates
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    80
        except TemplateError :
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    81
            raise
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    82
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    83
        except :
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    84
            # raise a TemplateError with the details
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    85
            details = exceptions.text_error_template().render()
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    86
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
    87
            raise TemplateError("Template render failed", status='500 Internal Server Error', details=details)
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    88
        
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    89
        else :
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    90
            # return the unicode data
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
    91
            return buf.getvalue()
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    93
    def lookup (self, name) :
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    94
        """
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    95
            Looks up a template based on the bare "name", which does not include the path or file extension
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    96
        """
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    97
        
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    98
        try :
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    99
            return self.get_template("%s.%s" % (name, self.fileext))
8
0ce1f471e9d7 and it works, a lot better than before
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   101
        except :
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   102
            raise TemplateError("Template broken: %r" % (name, ), status='500 Internal Server Error', details=exceptions.text_error_template().render())
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   103
    
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   104
    def render (self, name, **params) :
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   105
        """
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   106
            Render a template, using lookup() on the given name
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   107
        """
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   108
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   109
        return self._render(self.lookup(name), self.env, params)
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   110
40
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   111
    def render_to_response (self, name, **params) :
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   112
        """
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   113
            Render a template, returning a http.Response object
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   114
        """
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   115
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   116
        return http.Response(self.render(name, **params))
71ab68f31a1c the handlers work now
Tero Marttila <terom@fixme.fi>
parents: 32
diff changeset
   117
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   118
    def load (self, path) :
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   119
        """
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   120
            Loads a template from a specific file
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   121
        """
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   122
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   123
        try :
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   124
            return Template(filename=path, module_directory=CACHE_DIR)
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   125
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   126
        except :
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   127
            raise TemplateError("Template broken: %r" % (path, ), status='500 Internal Server Error', details=exceptions.text_error_template().render())
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   128
    
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   129
    def render_file (self, path, **params) :
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   130
        """
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   131
            Render a template, using load() on the given path. No global environment vars are defined for the render.
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   132
        """
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   133
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   134
        return self._render(self.load(path), dict(), params)
32
be954df4f0e8 move layout.tmpl to sites/www.qmsk.net
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   135
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   136
    def render_template (self, template, **params) :
42
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   137
        """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   138
            Render the given template object. No global environment vars are defined for the render.
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   139
        """
5a72c00c4ae4 more fiddling around with the irclogs layout/css, add query args to URL
Tero Marttila <terom@fixme.fi>
parents: 40
diff changeset
   140
        
50
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   141
        return self._render(template, dict(), params)
e4fbf480fbee change templates to remove all class/staticmethods, make Helpers a context-aware class, and fix defaults/URLIntegerType bugs in URLTree
Tero Marttila <terom@fixme.fi>
parents: 46
diff changeset
   142