~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-08 03:50:24 UTC
  • mfrom: (1294.2.143 ui-the-third)
  • Revision ID: grantw@unimelb.edu.au-20091208035024-wjx8zp54gth15ph8
Merge ui-the-third. This is another UI revamp.

The header is now thin! Thin! The yellow bar is gone. The tabs are gone.
Breadcrumbs are here. Routes is replaced (with an object publishing
mechanism). Views are less repetitive. etc.

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.publisher import NoPath
 
32
from ivle.webapp.breadcrumbs import Breadcrumber
31
33
 
32
34
class XHTMLView(BaseView):
33
35
    """
37
39
    """
38
40
 
39
41
    template = 'template.html'
40
 
 
41
 
    plugin_scripts = {}
42
 
    plugin_styles = {}
43
 
    scripts_init = []
44
 
 
45
42
    allow_overlays = True
46
 
    overlay_blacklist = []
47
 
 
48
 
    def __init__(self, req, **kwargs):
49
 
        for key in kwargs:
50
 
            setattr(self, key, kwargs[key])
 
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)
51
59
 
52
60
    def filter(self, stream, ctx):
53
61
        return stream
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")
 
108
        try:
 
109
            ctx['ancestry'] = self.get_context_ancestry(req)
 
110
        except NoPath:
 
111
            ctx['ancestry'] = []
 
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
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'
195
218
 
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
 
222
 
 
223
    def get_context_ancestry(self, req):
 
224
        return req.publisher.get_ancestors(self.lastobj)
198
225
 
199
226
    def populate(self, req, ctx):
 
227
        ctx['req'] = req
200
228
        ctx['exception'] = self.context
201
229
 
202
230
class XHTMLUnauthorizedView(XHTMLErrorView):
203
231
    template = 'xhtmlunauthorized.html'
204
232
 
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)
207
235
 
208
 
        if req.user is None:
 
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)
215
243
 
216
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