~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/base/xhtml.py

  • Committer: William Grant
  • Date: 2009-12-15 04:52:55 UTC
  • Revision ID: me@williamgrant.id.au-20091215045255-qsfeu9q2m4i5u7yy
Add exact match support to the TestFramework backend.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
31
from ivle.webapp.publisher import NoPath
 
32
from ivle.webapp.breadcrumbs import Breadcrumber
32
33
 
33
34
class XHTMLView(BaseView):
34
35
    """
38
39
    """
39
40
 
40
41
    template = 'template.html'
41
 
 
42
 
    plugin_scripts = {}
43
 
    plugin_styles = {}
44
 
    scripts_init = []
45
 
 
46
42
    allow_overlays = True
47
 
    overlay_blacklist = []
 
43
    breadcrumb_text = None
 
44
 
 
45
    def __init__(self, *args, **kwargs):
 
46
        super(XHTMLView, self).__init__(*args, **kwargs)
 
47
 
 
48
        self.overlay_blacklist = []
 
49
 
 
50
        self.plugin_scripts = {}
 
51
        self.plugin_styles = {}
 
52
        self.scripts_init = []
 
53
 
 
54
        self.extra_breadcrumbs = []
 
55
        self.overlay_blacklist = []
 
56
 
 
57
    def get_context_ancestry(self, req):
 
58
        return req.publisher.get_ancestors(self.context)
48
59
 
49
60
    def filter(self, stream, ctx):
50
61
        return stream
95
106
        ctx['title_img'] = media_url(req, CorePlugin,
96
107
                                     "images/chrome/root-breadcrumb.png")
97
108
        try:
98
 
            ctx['ancestry'] = req.router.get_ancestors(self.context)
 
109
            ctx['ancestry'] = self.get_context_ancestry(req)
99
110
        except NoPath:
100
111
            ctx['ancestry'] = []
101
 
        ctx['breadcrumb_text'] = lambda x: x # TODO: Do it properly.
102
 
        ctx['url'] = req.router.generate
 
112
 
 
113
        # If the view has specified text for a breadcrumb, add one.
 
114
        if self.breadcrumb_text:
 
115
            ctx['extra_breadcrumbs'] = [ViewBreadcrumb(req, self)]
 
116
        else:
 
117
            ctx['extra_breadcrumbs'] = []
 
118
 
 
119
        # Allow the view to add its own fake breadcrumbs.
 
120
        ctx['extra_breadcrumbs'] += self.extra_breadcrumbs
 
121
 
 
122
        ctx['crumb'] = Breadcrumber(req).crumb
103
123
        self.populate_headings(req, ctx)
104
124
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
105
125
                                                        'ivle-headings.html'))
196
216
class XHTMLErrorView(XHTMLView):
197
217
    template = 'xhtmlerror.html'
198
218
 
 
219
    def __init__(self, req, context, lastobj):
 
220
        super(XHTMLErrorView, self).__init__(req, context)
 
221
        self.lastobj = lastobj
 
222
 
 
223
    def get_context_ancestry(self, req):
 
224
        return req.publisher.get_ancestors(self.lastobj)
 
225
 
199
226
    def populate(self, req, ctx):
200
227
        ctx['req'] = req
201
228
        ctx['exception'] = self.context
203
230
class XHTMLUnauthorizedView(XHTMLErrorView):
204
231
    template = 'xhtmlunauthorized.html'
205
232
 
206
 
    def __init__(self, req, exception):
207
 
        super(XHTMLUnauthorizedView, self).__init__(req, exception)
 
233
    def __init__(self, req, exception, lastobj):
 
234
        super(XHTMLUnauthorizedView, self).__init__(req, exception, lastobj)
208
235
 
209
 
        if req.user is None:
 
236
        if not req.publicmode and req.user is None:
210
237
            # Not logged in. Redirect to login page.
211
238
            if req.uri == '/':
212
239
                query_string = ''
215
242
            req.throw_redirect('/+login' + query_string)
216
243
 
217
244
        req.status = 403
 
245
 
 
246
class ViewBreadcrumb(object):
 
247
    def __init__(self, req, context):
 
248
        self.req = req
 
249
        self.context = context
 
250
 
 
251
    @property
 
252
    def text(self):
 
253
        return self.context.breadcrumb_text