~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/xhtml.py

  • Committer: William Grant
  • Date: 2010-02-25 01:35:21 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225013521-yctd13gmq14wa3tm
Use a single (XHTMLView._loader, a class (not instance) variable) genshi TemplateLoader, so we can cache parsed templates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    template = 'template.html'
42
42
    allow_overlays = True
43
43
    breadcrumb_text = None
 
44
    _loader = None
44
45
 
45
46
    def __init__(self, *args, **kwargs):
46
47
        super(XHTMLView, self).__init__(*args, **kwargs)
47
48
 
 
49
        # We use a single loader for all views, so we can cache the
 
50
        # parsed templates. auto_reload is convenient and has a minimal
 
51
        # performance penalty, so we'll leave it on.
 
52
        if self.__class__._loader is None:
 
53
            self.__class__._loader = genshi.template.TemplateLoader(
 
54
                ".", auto_reload=True,
 
55
                max_cache_size=100)
 
56
 
48
57
        self.overlay_blacklist = []
49
58
 
50
59
        self.plugin_scripts = {}
71
80
        # view.
72
81
        app_template = os.path.join(os.path.dirname(
73
82
                        inspect.getmodule(self).__file__), self.template) 
74
 
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
75
 
        tmpl = loader.load(app_template)
 
83
        tmpl = self._loader.load(app_template)
76
84
        app = self.filter(tmpl.generate(viewctx), viewctx)
77
85
 
78
86
        view_scripts = []
133
141
            ctx['breadcrumbs'].extend(self.extra_breadcrumbs)
134
142
 
135
143
        self.populate_headings(req, ctx)
136
 
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
 
144
        tmpl = self._loader.load(os.path.join(os.path.dirname(__file__), 
137
145
                                                        'ivle-headings.html'))
138
146
        req.write(tmpl.generate(ctx).render('xhtml', doctype='xhtml'))
139
147