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
34
32
class XHTMLView(BaseView):
41
39
template = 'template.html'
42
45
allow_overlays = True
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)
46
overlay_blacklist = []
48
def __init__(self, req, **kwargs):
50
setattr(self, key, kwargs[key])
60
52
def filter(self, stream, ctx):
104
96
ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
105
97
ctx['app_template'] = app
106
98
ctx['title_img'] = media_url(req, CorePlugin,
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
99
"images/chrome/title.png")
123
100
self.populate_headings(req, ctx)
124
101
tmpl = loader.load(os.path.join(os.path.dirname(__file__),
125
102
'ivle-headings.html'))
216
193
class XHTMLErrorView(XHTMLView):
217
194
template = 'xhtmlerror.html'
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)
196
def __init__(self, req, exception):
197
self.context = exception
226
199
def populate(self, req, ctx):
228
200
ctx['exception'] = self.context
230
202
class XHTMLUnauthorizedView(XHTMLErrorView):
231
203
template = 'xhtmlunauthorized.html'
233
def __init__(self, req, exception, lastobj):
234
super(XHTMLUnauthorizedView, self).__init__(req, exception, lastobj)
205
def __init__(self, req, exception):
206
super(XHTMLUnauthorizedView, self).__init__(req, exception)
236
if not req.publicmode and req.user is None:
237
209
# Not logged in. Redirect to login page.
238
210
if req.uri == '/':
239
211
query_string = ''
242
214
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