~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-02 08:43:33 UTC
  • mto: (1294.2.118 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090802084333-j733m80q8hkrluaz
req.router -> req.publisher

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
 
47
 
    def __init__(self, req, **kwargs):
48
 
        for key in kwargs:
49
 
            setattr(self, key, kwargs[key])
 
48
    def filter(self, stream, ctx):
 
49
        return stream
50
50
 
51
51
    def render(self, req):
52
52
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
61
61
                        inspect.getmodule(self).__file__), self.template) 
62
62
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
63
63
        tmpl = loader.load(app_template)
64
 
        app = tmpl.generate(viewctx)
 
64
        app = self.filter(tmpl.generate(viewctx), viewctx)
65
65
 
 
66
        view_scripts = []
66
67
        for plugin in self.plugin_scripts:
67
68
            for path in self.plugin_scripts[plugin]:
68
 
                req.scripts.append(media_url(req, plugin, path))
 
69
                view_scripts.append(media_url(req, plugin, path))
69
70
 
 
71
        view_styles = []
70
72
        for plugin in self.plugin_styles:
71
73
            for path in self.plugin_styles[plugin]:
72
 
                req.styles.append(media_url(req, plugin, path))
 
74
                view_styles.append(media_url(req, plugin, path))
73
75
 
74
76
        # Global template
75
77
        ctx = genshi.template.Context()
76
 
        # XXX: Leave this here!! (Before req.styles is read)
77
 
        ctx['overlays'] = self.render_overlays(req) if req.user else []
 
78
 
 
79
        overlay_bits = self.render_overlays(req) if req.user else [[]]*4
 
80
        ctx['overlays'] = overlay_bits[0]
78
81
 
79
82
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
80
 
        ctx['styles'] += req.styles
 
83
        ctx['styles'] += view_styles
 
84
        ctx['styles'] += overlay_bits[1]
81
85
 
82
86
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
83
87
                           ('util.js', 'json2.js', 'md5.js')]
84
 
        ctx['scripts'] += req.scripts
 
88
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
 
89
        ctx['scripts'] += view_scripts
 
90
        ctx['scripts'] += overlay_bits[2]
85
91
 
86
 
        ctx['scripts_init'] = req.scripts_init
 
92
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
87
93
        ctx['app_template'] = app
88
94
        ctx['title_img'] = media_url(req, CorePlugin,
89
95
                                     "images/chrome/title.png")
97
103
 
98
104
    def populate_headings(self, req, ctx):
99
105
        ctx['favicon'] = None
100
 
        ctx['root_dir'] = ivle.conf.root_dir
101
 
        ctx['public_host'] = ivle.conf.public_host
 
106
        ctx['root_dir'] = req.config['urls']['root']
 
107
        ctx['public_host'] = req.config['urls']['public_host']
 
108
        ctx['svn_base'] = req.config['urls']['svn_addr']
102
109
        ctx['write_javascript_settings'] = req.write_javascript_settings
103
110
        if req.user:
104
111
            ctx['login'] = req.user.login
131
138
                        ctx['favicon'] = icon_url
132
139
                else:
133
140
                    new_app['has_icon'] = False
134
 
                new_app['path'] = ivle.util.make_path(tab[4])
 
141
                new_app['path'] = req.make_path(tab[4])
135
142
                new_app['desc'] = tab[2]
136
143
                new_app['name'] = tab[1]
137
144
                new_app['weight'] = tab[5]
146
153
        scripts_init.
147
154
        """
148
155
        overlays = []
 
156
        styles = []
 
157
        scripts = []
 
158
        scripts_init = []
149
159
        if not self.allow_overlays:
150
 
            return overlays
 
160
            return (overlays, styles, scripts, scripts_init)
151
161
 
152
162
        for plugin in req.config.plugin_index[OverlayPlugin]:
153
163
            for overclass in plugin.overlays:
157
167
                #TODO: Re-factor this to look nicer
158
168
                for mplugin in overlay.plugin_scripts:
159
169
                    for path in overlay.plugin_scripts[mplugin]:
160
 
                        req.scripts.append(media_url(req, mplugin, path))
 
170
                        scripts.append(media_url(req, mplugin, path))
161
171
 
162
172
                for mplugin in overlay.plugin_styles:
163
173
                    for path in overlay.plugin_styles[mplugin]:
164
 
                        req.styles.append(media_url(req, mplugin, path))
 
174
                        styles.append(media_url(req, mplugin, path))
165
175
 
166
 
                req.scripts_init += overlay.plugin_scripts_init
 
176
                scripts_init += overlay.plugin_scripts_init
167
177
 
168
178
                overlays.append(overlay.render(req))
169
 
        return overlays
 
179
        return (overlays, styles, scripts, scripts_init)
170
180
 
171
181
    @classmethod
172
182
    def get_error_view(cls, e):
179
189
class XHTMLErrorView(XHTMLView):
180
190
    template = 'xhtmlerror.html'
181
191
 
182
 
    def __init__(self, req, exception):
183
 
        self.context = exception
184
 
 
185
192
    def populate(self, req, ctx):
 
193
        ctx['req'] = req
186
194
        ctx['exception'] = self.context
187
195
 
188
196
class XHTMLUnauthorizedView(XHTMLErrorView):