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'
45
42
allow_overlays = True
46
overlay_blacklist = []
48
def __init__(self, req, **kwargs):
50
setattr(self, key, kwargs[key])
43
breadcrumb_text = None
45
def __init__(self, *args, **kwargs):
46
super(XHTMLView, self).__init__(*args, **kwargs)
48
self.overlay_blacklist = []
50
self.plugin_scripts = {}
51
self.plugin_styles = {}
52
self.scripts_init = []
54
self.extra_breadcrumbs = []
55
self.overlay_blacklist = []
57
def get_context_ancestry(self, req):
58
return req.publisher.get_ancestors(self.context)
52
60
def filter(self, stream, ctx):
96
104
ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
97
105
ctx['app_template'] = app
98
106
ctx['title_img'] = media_url(req, CorePlugin,
99
"images/chrome/title.png")
107
"images/chrome/root-breadcrumb.png")
109
ctx['ancestry'] = self.get_context_ancestry(req)
113
# If the view has specified text for a breadcrumb, add one.
114
if self.breadcrumb_text:
115
ctx['extra_breadcrumbs'] = [ViewBreadcrumb(req, self)]
117
ctx['extra_breadcrumbs'] = []
119
# Allow the view to add its own fake breadcrumbs.
120
ctx['extra_breadcrumbs'] += self.extra_breadcrumbs
122
ctx['crumb'] = Breadcrumber(req).crumb
100
123
self.populate_headings(req, ctx)
101
124
tmpl = loader.load(os.path.join(os.path.dirname(__file__),
102
125
'ivle-headings.html'))
193
216
class XHTMLErrorView(XHTMLView):
194
217
template = 'xhtmlerror.html'
196
def __init__(self, req, exception):
197
self.context = exception
219
def __init__(self, req, context, lastobj):
220
super(XHTMLErrorView, self).__init__(req, context)
221
self.lastobj = lastobj
223
def get_context_ancestry(self, req):
224
return req.publisher.get_ancestors(self.lastobj)
199
226
def populate(self, req, ctx):
200
228
ctx['exception'] = self.context
202
230
class XHTMLUnauthorizedView(XHTMLErrorView):
203
231
template = 'xhtmlunauthorized.html'
205
def __init__(self, req, exception):
206
super(XHTMLUnauthorizedView, self).__init__(req, exception)
233
def __init__(self, req, exception, lastobj):
234
super(XHTMLUnauthorizedView, self).__init__(req, exception, lastobj)
236
if not req.publicmode and req.user is None:
209
237
# Not logged in. Redirect to login page.
210
238
if req.uri == '/':
211
239
query_string = ''
214
242
req.throw_redirect('/+login' + query_string)
246
class ViewBreadcrumb(object):
247
def __init__(self, req, context):
249
self.context = context
253
return self.context.breadcrumb_text