~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-02-25 23:04:11 UTC
  • Revision ID: grantw@unimelb.edu.au-20090225230411-lbdyl32ir0m3d59b
Make all of the services executable.

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