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

« back to all changes in this revision

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

ivle.webapp.base.xhtml.XHTMLView: Split the global and view contexts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    def __init__(self, req, **kwargs):
36
36
        for key in kwargs:
37
37
          setattr(self, key, kwargs[key])
38
 
        
 
38
 
39
39
    def render(self, req):
40
40
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
41
 
        ctx = genshi.template.Context()
42
 
        self.populate(req, ctx)
43
 
        self.populate_headings(req, ctx)
44
 
        
45
 
        ctx['app_styles'] = req.styles
46
 
        ctx['scripts'] = req.scripts
47
 
        ctx['scripts_init'] = req.scripts_init
 
41
 
 
42
        # View template
 
43
        viewctx = genshi.template.Context()
 
44
        self.populate(req, viewctx)
 
45
 
 
46
        # The template is found in the directory of the module containing the
 
47
        # view.
48
48
        app_template = os.path.join(os.path.dirname(
49
49
                        inspect.getmodule(self).__file__), self.template) 
50
50
        req.write_html_head_foot = False
51
51
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
52
52
        tmpl = loader.load(app_template)
53
 
        app = tmpl.generate(ctx)
 
53
        app = tmpl.generate(viewctx)
 
54
 
 
55
        # Global template
 
56
        ctx = genshi.template.Context()
 
57
        ctx['app_styles'] = req.styles
 
58
        ctx['scripts'] = req.scripts
 
59
        ctx['scripts_init'] = req.scripts_init
54
60
        ctx['app_template'] = app
 
61
        self.populate_headings(req, ctx)
55
62
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
56
63
                                                        'ivle-headings.html'))
57
64
        req.write(tmpl.generate(ctx).render('xhtml', doctype='xhtml'))