~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-08-12 04:30:38 UTC
  • Revision ID: grantw@unimelb.edu.au-20090812043038-pil4b76apx9rw86x
Allow tutors to add exercises.

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
    """
39
37
    """
40
38
 
41
39
    template = 'template.html'
 
40
 
42
41
    plugin_scripts = {}
43
42
    plugin_styles = {}
 
43
    scripts_init = []
 
44
 
44
45
    allow_overlays = True
45
46
    overlay_blacklist = []
46
47
 
66
67
        tmpl = loader.load(app_template)
67
68
        app = self.filter(tmpl.generate(viewctx), viewctx)
68
69
 
 
70
        view_scripts = []
69
71
        for plugin in self.plugin_scripts:
70
72
            for path in self.plugin_scripts[plugin]:
71
 
                req.scripts.append(media_url(req, plugin, path))
 
73
                view_scripts.append(media_url(req, plugin, path))
72
74
 
 
75
        view_styles = []
73
76
        for plugin in self.plugin_styles:
74
77
            for path in self.plugin_styles[plugin]:
75
 
                req.styles.append(media_url(req, plugin, path))
 
78
                view_styles.append(media_url(req, plugin, path))
76
79
 
77
80
        # Global template
78
81
        ctx = genshi.template.Context()
79
 
        # XXX: Leave this here!! (Before req.styles is read)
80
 
        ctx['overlays'] = self.render_overlays(req) if req.user else []
 
82
 
 
83
        overlay_bits = self.render_overlays(req) if req.user else [[]]*4
 
84
        ctx['overlays'] = overlay_bits[0]
81
85
 
82
86
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
83
 
        ctx['styles'] += req.styles
 
87
        ctx['styles'] += view_styles
 
88
        ctx['styles'] += overlay_bits[1]
84
89
 
85
90
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
86
91
                           ('util.js', 'json2.js', 'md5.js')]
87
92
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
88
 
        ctx['scripts'] += req.scripts
 
93
        ctx['scripts'] += view_scripts
 
94
        ctx['scripts'] += overlay_bits[2]
89
95
 
90
 
        ctx['scripts_init'] = req.scripts_init
 
96
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
91
97
        ctx['app_template'] = app
92
98
        ctx['title_img'] = media_url(req, CorePlugin,
93
99
                                     "images/chrome/title.png")
101
107
 
102
108
    def populate_headings(self, req, ctx):
103
109
        ctx['favicon'] = None
104
 
        ctx['root_dir'] = ivle.conf.root_dir
105
 
        ctx['public_host'] = ivle.conf.public_host
106
 
        ctx['svn_base'] = ivle.conf.svn_addr
 
110
        ctx['root_dir'] = req.config['urls']['root']
 
111
        ctx['public_host'] = req.config['urls']['public_host']
 
112
        ctx['svn_base'] = req.config['urls']['svn_addr']
107
113
        ctx['write_javascript_settings'] = req.write_javascript_settings
108
114
        if req.user:
109
115
            ctx['login'] = req.user.login
136
142
                        ctx['favicon'] = icon_url
137
143
                else:
138
144
                    new_app['has_icon'] = False
139
 
                new_app['path'] = ivle.util.make_path(tab[4])
 
145
                new_app['path'] = req.make_path(tab[4])
140
146
                new_app['desc'] = tab[2]
141
147
                new_app['name'] = tab[1]
142
148
                new_app['weight'] = tab[5]
151
157
        scripts_init.
152
158
        """
153
159
        overlays = []
 
160
        styles = []
 
161
        scripts = []
 
162
        scripts_init = []
154
163
        if not self.allow_overlays:
155
 
            return overlays
 
164
            return (overlays, styles, scripts, scripts_init)
156
165
 
157
166
        for plugin in req.config.plugin_index[OverlayPlugin]:
158
167
            for overclass in plugin.overlays:
162
171
                #TODO: Re-factor this to look nicer
163
172
                for mplugin in overlay.plugin_scripts:
164
173
                    for path in overlay.plugin_scripts[mplugin]:
165
 
                        req.scripts.append(media_url(req, mplugin, path))
 
174
                        scripts.append(media_url(req, mplugin, path))
166
175
 
167
176
                for mplugin in overlay.plugin_styles:
168
177
                    for path in overlay.plugin_styles[mplugin]:
169
 
                        req.styles.append(media_url(req, mplugin, path))
 
178
                        styles.append(media_url(req, mplugin, path))
170
179
 
171
 
                req.scripts_init += overlay.plugin_scripts_init
 
180
                scripts_init += overlay.plugin_scripts_init
172
181
 
173
182
                overlays.append(overlay.render(req))
174
 
        return overlays
 
183
        return (overlays, styles, scripts, scripts_init)
175
184
 
176
185
    @classmethod
177
186
    def get_error_view(cls, e):