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
from ivle.webapp.routing import NoPath
32
33
class XHTMLView(BaseView):
39
40
template = 'template.html'
40
42
plugin_scripts = {}
42
46
allow_overlays = True
43
47
overlay_blacklist = []
45
def __init__(self, req, **kwargs):
47
setattr(self, key, kwargs[key])
49
49
def filter(self, stream, ctx):
64
64
tmpl = loader.load(app_template)
65
65
app = self.filter(tmpl.generate(viewctx), viewctx)
67
68
for plugin in self.plugin_scripts:
68
69
for path in self.plugin_scripts[plugin]:
69
req.scripts.append(media_url(req, plugin, path))
70
view_scripts.append(media_url(req, plugin, path))
71
73
for plugin in self.plugin_styles:
72
74
for path in self.plugin_styles[plugin]:
73
req.styles.append(media_url(req, plugin, path))
75
view_styles.append(media_url(req, plugin, path))
76
78
ctx = genshi.template.Context()
77
# XXX: Leave this here!! (Before req.styles is read)
78
ctx['overlays'] = self.render_overlays(req) if req.user else []
80
overlay_bits = self.render_overlays(req) if req.user else [[]]*4
81
ctx['overlays'] = overlay_bits[0]
80
83
ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
81
ctx['styles'] += req.styles
84
ctx['styles'] += view_styles
85
ctx['styles'] += overlay_bits[1]
83
87
ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
84
88
('util.js', 'json2.js', 'md5.js')]
85
89
ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
86
ctx['scripts'] += req.scripts
90
ctx['scripts'] += view_scripts
91
ctx['scripts'] += overlay_bits[2]
88
ctx['scripts_init'] = req.scripts_init
93
ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
89
94
ctx['app_template'] = app
90
95
ctx['title_img'] = media_url(req, CorePlugin,
91
"images/chrome/title.png")
96
"images/chrome/root-breadcrumb.png")
98
ctx['ancestry'] = req.router.get_ancestors(self.context)
101
ctx['breadcrumb_text'] = lambda x: x # TODO: Do it properly.
102
ctx['url'] = req.router.generate
92
103
self.populate_headings(req, ctx)
93
104
tmpl = loader.load(os.path.join(os.path.dirname(__file__),
94
105
'ivle-headings.html'))
160
174
#TODO: Re-factor this to look nicer
161
175
for mplugin in overlay.plugin_scripts:
162
176
for path in overlay.plugin_scripts[mplugin]:
163
req.scripts.append(media_url(req, mplugin, path))
177
scripts.append(media_url(req, mplugin, path))
165
179
for mplugin in overlay.plugin_styles:
166
180
for path in overlay.plugin_styles[mplugin]:
167
req.styles.append(media_url(req, mplugin, path))
181
styles.append(media_url(req, mplugin, path))
169
req.scripts_init += overlay.plugin_scripts_init
183
scripts_init += overlay.plugin_scripts_init
171
185
overlays.append(overlay.render(req))
186
return (overlays, styles, scripts, scripts_init)
175
189
def get_error_view(cls, e):
182
196
class XHTMLErrorView(XHTMLView):
183
197
template = 'xhtmlerror.html'
185
def __init__(self, req, exception):
186
self.context = exception
188
199
def populate(self, req, ctx):
189
201
ctx['exception'] = self.context
191
203
class XHTMLUnauthorizedView(XHTMLErrorView):