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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-02-27 00:00:38 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:594
Added to doc/setup/faq.txt: sessions directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE - Informatics Virtual Learning Environment
2
 
# Copyright (C) 2007-2009 The University of Melbourne
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
# Author: Nick Chadwick
19
 
 
20
 
import inspect
21
 
import os.path
22
 
 
23
 
import genshi.template
24
 
 
25
 
from ivle.webapp.base.views import BaseView
26
 
import ivle.conf
27
 
import ivle.util
28
 
 
29
 
class XHTMLView(BaseView):
30
 
    """
31
 
    A view which provides a base class for views which need to return XHTML
32
 
    It is expected that apps which use this view will be written using Genshi
33
 
    templates.
34
 
    """
35
 
    def __init__(self, req, **kwargs):
36
 
        for key in kwargs:
37
 
            setattr(self, key, kwargs[key])
38
 
 
39
 
    def render(self, req):
40
 
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
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
 
        app_template = os.path.join(os.path.dirname(
49
 
                        inspect.getmodule(self).__file__), self.template) 
50
 
        req.write_html_head_foot = False
51
 
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
52
 
        tmpl = loader.load(app_template)
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
60
 
        ctx['app_template'] = app
61
 
        self.populate_headings(req, ctx)
62
 
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
63
 
                                                        'ivle-headings.html'))
64
 
        req.write(tmpl.generate(ctx).render('xhtml', doctype='xhtml'))
65
 
 
66
 
    def populate_headings(self, req, ctx):
67
 
        ctx['favicon'] = None
68
 
        ctx['root_dir'] = ivle.conf.root_dir
69
 
        ctx['public_host'] = ivle.conf.public_host
70
 
        ctx['write_javascript_settings'] = req.write_javascript_settings
71
 
        if req.user:
72
 
            ctx['login'] = req.user.login
73
 
            ctx['logged_in'] = True
74
 
            ctx['nick'] = req.user.nick
75
 
        else:
76
 
            ctx['login'] = None
77
 
        ctx['publicmode'] = req.publicmode
78
 
        ctx['apps_in_tabs'] = []
79
 
        for urlname in ivle.conf.apps.apps_in_tabs:
80
 
            new_app = {}
81
 
            app = ivle.conf.apps.app_url[urlname]
82
 
            new_app['this_app'] = hasattr(self, 'appname') \
83
 
                                  and urlname == self.appname
84
 
            if app.icon:
85
 
                new_app['has_icon'] = True
86
 
                icon_dir = ivle.conf.apps.app_icon_dir
87
 
                icon_url = ivle.util.make_path(os.path.join(icon_dir, app.icon))
88
 
                new_app['icon_url'] = icon_url
89
 
                if new_app['this_app']:
90
 
                    ctx['favicon'] = icon_url
91
 
            else:
92
 
                new_app['has_icon'] = False
93
 
            new_app['path'] = ivle.util.make_path(urlname)
94
 
            new_app['desc'] = app.desc
95
 
            new_app['name'] = app.name
96
 
            ctx['apps_in_tabs'].append(new_app)