~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-15 08:49:58 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215084958-8x5dzd9k4pbcddlz
Split subject/semester management out onto a separate page, and link to SemesterEdit.

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
 
 
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):
 
34
class XHTMLView(BaseView):
56
35
    """
57
36
    A view which provides a base class for views which need to return XHTML
58
37
    It is expected that apps which use this view will be written using Genshi
92
71
        # view.
93
72
        app_template = os.path.join(os.path.dirname(
94
73
                        inspect.getmodule(self).__file__), self.template) 
95
 
        tmpl = self._loader.load(app_template)
 
74
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
 
75
        tmpl = loader.load(app_template)
96
76
        app = self.filter(tmpl.generate(viewctx), viewctx)
97
77
 
98
78
        view_scripts = []
153
133
            ctx['breadcrumbs'].extend(self.extra_breadcrumbs)
154
134
 
155
135
        self.populate_headings(req, ctx)
156
 
        tmpl = self._loader.load(os.path.join(os.path.dirname(__file__), 
 
136
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
157
137
                                                        'ivle-headings.html'))
158
138
        req.write(tmpl.generate(ctx).render('xhtml', doctype='xhtml'))
159
139
        
265
245
    def populate(self, req, ctx):
266
246
        ctx['req'] = req
267
247
        ctx['exception'] = self.context
268
 
        req.headers_out['X-IVLE-Error'] = self.context.message
269
248
 
270
249
class XHTMLUnauthorizedView(XHTMLErrorView):
271
250
    template = 'xhtmlunauthorized.html'