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.publisher import NoPath
32
from ivle.webapp.breadcrumbs import Breadcrumber
32
34
class XHTMLView(BaseView):
39
41
template = 'template.html'
42
42
allow_overlays = True
43
overlay_blacklist = []
45
def __init__(self, req, **kwargs):
47
setattr(self, key, kwargs[key])
44
def __init__(self, *args, **kwargs):
45
super(XHTMLView, self).__init__(*args, **kwargs)
47
self.overlay_blacklist = []
49
self.plugin_scripts = {}
50
self.plugin_styles = {}
51
self.scripts_init = []
53
self.extra_breadcrumbs = []
54
self.overlay_blacklist = []
56
def get_context_ancestry(self, req):
57
return req.publisher.get_ancestors(self.context)
49
59
def filter(self, stream, ctx):
64
74
tmpl = loader.load(app_template)
65
75
app = self.filter(tmpl.generate(viewctx), viewctx)
67
78
for plugin in self.plugin_scripts:
68
79
for path in self.plugin_scripts[plugin]:
69
req.scripts.append(media_url(req, plugin, path))
80
view_scripts.append(media_url(req, plugin, path))
71
83
for plugin in self.plugin_styles:
72
84
for path in self.plugin_styles[plugin]:
73
req.styles.append(media_url(req, plugin, path))
85
view_styles.append(media_url(req, plugin, path))
76
88
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 []
90
overlay_bits = self.render_overlays(req) if req.user else [[]]*4
91
ctx['overlays'] = overlay_bits[0]
80
93
ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
81
ctx['styles'] += req.styles
94
ctx['styles'] += view_styles
95
ctx['styles'] += overlay_bits[1]
83
97
ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
84
98
('util.js', 'json2.js', 'md5.js')]
85
99
ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
86
ctx['scripts'] += req.scripts
100
ctx['scripts'] += view_scripts
101
ctx['scripts'] += overlay_bits[2]
88
ctx['scripts_init'] = req.scripts_init
103
ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
89
104
ctx['app_template'] = app
90
105
ctx['title_img'] = media_url(req, CorePlugin,
91
"images/chrome/title.png")
106
"images/chrome/root-breadcrumb.png")
108
ctx['ancestry'] = self.get_context_ancestry(req)
112
# Allow the view to add its own fake breadcrumbs.
113
ctx['extra_breadcrumbs'] = self.extra_breadcrumbs
115
ctx['crumb'] = Breadcrumber(req).crumb
92
116
self.populate_headings(req, ctx)
93
117
tmpl = loader.load(os.path.join(os.path.dirname(__file__),
94
118
'ivle-headings.html'))
160
187
#TODO: Re-factor this to look nicer
161
188
for mplugin in overlay.plugin_scripts:
162
189
for path in overlay.plugin_scripts[mplugin]:
163
req.scripts.append(media_url(req, mplugin, path))
190
scripts.append(media_url(req, mplugin, path))
165
192
for mplugin in overlay.plugin_styles:
166
193
for path in overlay.plugin_styles[mplugin]:
167
req.styles.append(media_url(req, mplugin, path))
194
styles.append(media_url(req, mplugin, path))
169
req.scripts_init += overlay.plugin_scripts_init
196
scripts_init += overlay.plugin_scripts_init
171
198
overlays.append(overlay.render(req))
199
return (overlays, styles, scripts, scripts_init)
175
202
def get_error_view(cls, e):
182
209
class XHTMLErrorView(XHTMLView):
183
210
template = 'xhtmlerror.html'
185
def __init__(self, req, exception):
186
self.context = exception
212
def __init__(self, req, context, lastobj):
213
super(XHTMLErrorView, self).__init__(req, context)
214
self.lastobj = lastobj
216
def get_context_ancestry(self, req):
217
return req.publisher.get_ancestors(self.lastobj)
188
219
def populate(self, req, ctx):
189
221
ctx['exception'] = self.context
191
223
class XHTMLUnauthorizedView(XHTMLErrorView):
192
224
template = 'xhtmlunauthorized.html'
194
def __init__(self, req, exception):
195
super(XHTMLUnauthorizedView, self).__init__(req, exception)
226
def __init__(self, req, exception, lastobj):
227
super(XHTMLUnauthorizedView, self).__init__(req, exception, lastobj)
197
229
if req.user is None:
198
230
# Not logged in. Redirect to login page.