41
39
template = 'template.html'
42
41
plugin_scripts = {}
44
45
allow_overlays = True
45
46
overlay_blacklist = []
47
def __init__(self, req, **kwargs):
49
setattr(self, key, kwargs[key])
48
def filter(self, stream, ctx):
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)
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))
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))
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 []
79
overlay_bits = self.render_overlays(req) if req.user else [[]]*4
80
ctx['overlays'] = overlay_bits[0]
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]
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]
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")
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
104
111
ctx['login'] = req.user.login
149
159
if not self.allow_overlays:
160
return (overlays, styles, scripts, scripts_init)
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))
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))
166
req.scripts_init += overlay.plugin_scripts_init
176
scripts_init += overlay.plugin_scripts_init
168
178
overlays.append(overlay.render(req))
179
return (overlays, styles, scripts, scripts_init)
172
182
def get_error_view(cls, e):
179
189
class XHTMLErrorView(XHTMLView):
180
190
template = 'xhtmlerror.html'
182
def __init__(self, req, exception):
183
self.context = exception
185
192
def populate(self, req, ctx):
186
194
ctx['exception'] = self.context
188
196
class XHTMLUnauthorizedView(XHTMLErrorView):