~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-26 06:33:35 UTC
  • Revision ID: grantw@unimelb.edu.au-20100226063335-25ka31up8cegwaiz
ivle.interpret.execute_raw now sets a clean environment, in particular with HOME set correctly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from ivle.webapp.publisher import NoPath
32
32
from ivle.webapp.breadcrumbs import Breadcrumber
33
33
 
34
 
class XHTMLView(BaseView):
 
34
 
 
35
class GenshiLoaderMixin(object):
 
36
    """Mixin for classes which need to render Genshi templates.
 
37
 
 
38
    A TemplateLoader is shared between all instances, so templates are
 
39
    cached across multiple instances and therefore also requests.
 
40
    """
 
41
    _loader = None
 
42
 
 
43
    def __init__(self, *args, **kwargs):
 
44
        super(GenshiLoaderMixin, self).__init__(*args, **kwargs)
 
45
 
 
46
        # We use a single loader for all views, so we can cache the
 
47
        # parsed templates. auto_reload is convenient and has a minimal
 
48
        # performance penalty, so we'll leave it on.
 
49
        if GenshiLoaderMixin._loader is None:
 
50
            GenshiLoaderMixin._loader = genshi.template.TemplateLoader(
 
51
                ".", auto_reload=True,
 
52
                max_cache_size=100)
 
53
 
 
54
 
 
55
class XHTMLView(GenshiLoaderMixin, BaseView):
35
56
    """
36
57
    A view which provides a base class for views which need to return XHTML
37
58
    It is expected that apps which use this view will be written using Genshi
71
92
        # view.
72
93
        app_template = os.path.join(os.path.dirname(
73
94
                        inspect.getmodule(self).__file__), self.template) 
74
 
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
75
 
        tmpl = loader.load(app_template)
 
95
        tmpl = self._loader.load(app_template)
76
96
        app = self.filter(tmpl.generate(viewctx), viewctx)
77
97
 
78
98
        view_scripts = []
133
153
            ctx['breadcrumbs'].extend(self.extra_breadcrumbs)
134
154
 
135
155
        self.populate_headings(req, ctx)
136
 
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
 
156
        tmpl = self._loader.load(os.path.join(os.path.dirname(__file__), 
137
157
                                                        'ivle-headings.html'))
138
158
        req.write(tmpl.generate(ctx).render('xhtml', doctype='xhtml'))
139
159
        
245
265
    def populate(self, req, ctx):
246
266
        ctx['req'] = req
247
267
        ctx['exception'] = self.context
 
268
        req.headers_out['X-IVLE-Error'] = self.context.message
248
269
 
249
270
class XHTMLUnauthorizedView(XHTMLErrorView):
250
271
    template = 'xhtmlunauthorized.html'