~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: 2009-12-08 02:10:26 UTC
  • Revision ID: coles.david@gmail.com-20091208021026-3a27ecdzm49y39me
Configuration documentation - fixing a few references

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
33
31
 
34
32
class XHTMLView(BaseView):
35
33
    """
39
37
    """
40
38
 
41
39
    template = 'template.html'
 
40
 
 
41
    plugin_scripts = {}
 
42
    plugin_styles = {}
 
43
    scripts_init = []
 
44
 
42
45
    allow_overlays = True
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)
 
46
    overlay_blacklist = []
 
47
 
 
48
    def __init__(self, req, **kwargs):
 
49
        for key in kwargs:
 
50
            setattr(self, key, kwargs[key])
59
51
 
60
52
    def filter(self, stream, ctx):
61
53
        return stream
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")
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
 
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'
218
195
 
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)
 
196
    def __init__(self, req, exception):
 
197
        self.context = exception
225
198
 
226
199
    def populate(self, req, ctx):
227
 
        ctx['req'] = req
228
200
        ctx['exception'] = self.context
229
201
 
230
202
class XHTMLUnauthorizedView(XHTMLErrorView):
231
203
    template = 'xhtmlunauthorized.html'
232
204
 
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)
235
207
 
236
 
        if not req.publicmode and req.user is None:
 
208
        if 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)
243
215
 
244
216
        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