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

« back to all changes in this revision

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

  • Committer: David Coles
  • Date: 2010-02-04 01:10:11 UTC
  • Revision ID: coles.david@gmail.com-20100204011011-f7fp96dw1lac4w3o
Docs: Clarification that debuild should be run in the package directory, not 
parent.

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
            ancestry = self.get_context_ancestry(req)
 
110
        except NoPath:
 
111
            ancestry = []
 
112
 
 
113
        crumber = Breadcrumber(req)
 
114
 
 
115
        ctx['breadcrumbs'] = []
 
116
        for ancestor in ancestry:
 
117
            crumb = crumber.crumb(ancestor)
 
118
            if crumb is None:
 
119
                continue
 
120
 
 
121
            if hasattr(crumb, 'extra_breadcrumbs_before'):
 
122
                ctx['breadcrumbs'].extend(crumb.extra_breadcrumbs_before)
 
123
            ctx['breadcrumbs'].append(crumb)
 
124
            if hasattr(crumb, 'extra_breadcrumbs_after'):
 
125
                ctx['breadcrumbs'].extend(crumb.extra_breadcrumbs_after)
 
126
 
 
127
        # If the view has specified text for a breadcrumb, add one.
 
128
        if self.breadcrumb_text:
 
129
            ctx['breadcrumbs'].append(ViewBreadcrumb(req, self))
 
130
 
 
131
        # Allow the view to add its own fake breadcrumbs.
 
132
        ctx['breadcrumbs'].extend(self.extra_breadcrumbs)
 
133
 
100
134
        self.populate_headings(req, ctx)
101
135
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
102
136
                                                        'ivle-headings.html'))
193
227
class XHTMLErrorView(XHTMLView):
194
228
    template = 'xhtmlerror.html'
195
229
 
196
 
    def __init__(self, req, exception):
197
 
        self.context = exception
 
230
    def __init__(self, req, context, lastobj):
 
231
        super(XHTMLErrorView, self).__init__(req, context)
 
232
        self.lastobj = lastobj
 
233
 
 
234
    def get_context_ancestry(self, req):
 
235
        return req.publisher.get_ancestors(self.lastobj)
198
236
 
199
237
    def populate(self, req, ctx):
 
238
        ctx['req'] = req
200
239
        ctx['exception'] = self.context
201
240
 
202
241
class XHTMLUnauthorizedView(XHTMLErrorView):
203
242
    template = 'xhtmlunauthorized.html'
204
243
 
205
 
    def __init__(self, req, exception):
206
 
        super(XHTMLUnauthorizedView, self).__init__(req, exception)
 
244
    def __init__(self, req, exception, lastobj):
 
245
        super(XHTMLUnauthorizedView, self).__init__(req, exception, lastobj)
207
246
 
208
 
        if req.user is None:
 
247
        if not req.publicmode and req.user is None:
209
248
            # Not logged in. Redirect to login page.
210
249
            if req.uri == '/':
211
250
                query_string = ''
214
253
            req.throw_redirect('/+login' + query_string)
215
254
 
216
255
        req.status = 403
 
256
 
 
257
class ViewBreadcrumb(object):
 
258
    def __init__(self, req, context):
 
259
        self.req = req
 
260
        self.context = context
 
261
 
 
262
    @property
 
263
    def text(self):
 
264
        return self.context.breadcrumb_text