~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: 2009-04-28 07:08:56 UTC
  • Revision ID: grantw@unimelb.edu.au-20090428070856-75yc00g6ea24qfqz
Drop ivle.conf.{subjects,exercises}_base - they were unused.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from ivle.webapp.base.views import BaseView
29
29
from ivle.webapp.base.plugins import ViewPlugin, OverlayPlugin
30
30
from ivle.webapp.errors import HTTPError, Unauthorized
31
 
import ivle.conf
32
 
import ivle.util
33
31
 
34
32
class XHTMLView(BaseView):
35
33
    """
48
46
        for key in kwargs:
49
47
            setattr(self, key, kwargs[key])
50
48
 
 
49
    def filter(self, stream, ctx):
 
50
        return stream
 
51
 
51
52
    def render(self, req):
52
53
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
53
54
 
61
62
                        inspect.getmodule(self).__file__), self.template) 
62
63
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
63
64
        tmpl = loader.load(app_template)
64
 
        app = tmpl.generate(viewctx)
 
65
        app = self.filter(tmpl.generate(viewctx), viewctx)
65
66
 
66
67
        for plugin in self.plugin_scripts:
67
68
            for path in self.plugin_scripts[plugin]:
74
75
        # Global template
75
76
        ctx = genshi.template.Context()
76
77
        # XXX: Leave this here!! (Before req.styles is read)
77
 
        ctx['overlays'] = self.render_overlays(req)
 
78
        ctx['overlays'] = self.render_overlays(req) if req.user else []
78
79
 
79
80
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
80
81
        ctx['styles'] += req.styles
81
82
 
82
83
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
83
84
                           ('util.js', 'json2.js', 'md5.js')]
 
85
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
84
86
        ctx['scripts'] += req.scripts
85
87
 
86
88
        ctx['scripts_init'] = req.scripts_init
87
89
        ctx['app_template'] = app
 
90
        ctx['title_img'] = media_url(req, CorePlugin,
 
91
                                     "images/chrome/title.png")
88
92
        self.populate_headings(req, ctx)
89
93
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
90
94
                                                        'ivle-headings.html'))
95
99
 
96
100
    def populate_headings(self, req, ctx):
97
101
        ctx['favicon'] = None
98
 
        ctx['root_dir'] = ivle.conf.root_dir
99
 
        ctx['public_host'] = ivle.conf.public_host
 
102
        ctx['root_dir'] = req.config['urls']['root']
 
103
        ctx['public_host'] = req.config['urls']['public_host']
 
104
        ctx['svn_base'] = req.config['urls']['svn_addr']
100
105
        ctx['write_javascript_settings'] = req.write_javascript_settings
101
106
        if req.user:
102
107
            ctx['login'] = req.user.login
117
122
            for tab in plugin.tabs:
118
123
                # tab is a tuple: name, title, desc, icon, path
119
124
                new_app = {}
120
 
                new_app['this_app'] = hasattr(self, 'appname') \
121
 
                                      and tab[0] == self.appname
 
125
                new_app['this_app'] = hasattr(self, 'tab') \
 
126
                                      and tab[0] == self.tab
122
127
 
123
128
                # Icon name
124
129
                if tab[3] is not None:
129
134
                        ctx['favicon'] = icon_url
130
135
                else:
131
136
                    new_app['has_icon'] = False
132
 
                new_app['path'] = ivle.util.make_path(tab[4])
 
137
                new_app['path'] = req.make_path(tab[4])
133
138
                new_app['desc'] = tab[2]
134
139
                new_app['name'] = tab[1]
135
140
                new_app['weight'] = tab[5]
191
196
 
192
197
        if req.user is None:
193
198
            # Not logged in. Redirect to login page.
194
 
            req.throw_redirect('/+login?' + 
195
 
                               urllib.urlencode([('url', req.uri)]))
 
199
            if req.uri == '/':
 
200
                query_string = ''
 
201
            else:
 
202
                query_string = '?url=' + urllib.quote(req.uri, safe="/~")
 
203
            req.throw_redirect('/+login' + query_string)
196
204
 
197
205
        req.status = 403