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

« back to all changes in this revision

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

Merge from object-publishing.

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
 
 
44
    def __init__(self, *args, **kwargs):
 
45
        super(XHTMLView, self).__init__(*args, **kwargs)
 
46
 
 
47
        self.overlay_blacklist = []
 
48
 
 
49
        self.plugin_scripts = {}
 
50
        self.plugin_styles = {}
 
51
        self.scripts_init = []
 
52
 
 
53
        self.extra_breadcrumbs = []
 
54
        self.overlay_blacklist = []
 
55
 
 
56
    def get_context_ancestry(self, req):
 
57
        return req.publisher.get_ancestors(self.context)
48
58
 
49
59
    def filter(self, stream, ctx):
50
60
        return stream
95
105
        ctx['title_img'] = media_url(req, CorePlugin,
96
106
                                     "images/chrome/root-breadcrumb.png")
97
107
        try:
98
 
            ctx['ancestry'] = req.router.get_ancestors(self.context)
 
108
            ctx['ancestry'] = self.get_context_ancestry(req)
99
109
        except NoPath:
100
110
            ctx['ancestry'] = []
101
 
        ctx['breadcrumb_text'] = lambda x: x # TODO: Do it properly.
102
 
        ctx['url'] = req.router.generate
 
111
 
 
112
        # Allow the view to add its own fake breadcrumbs.
 
113
        ctx['extra_breadcrumbs'] = self.extra_breadcrumbs
 
114
 
 
115
        ctx['crumb'] = Breadcrumber(req).crumb
103
116
        self.populate_headings(req, ctx)
104
117
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
105
118
                                                        'ivle-headings.html'))
196
209
class XHTMLErrorView(XHTMLView):
197
210
    template = 'xhtmlerror.html'
198
211
 
 
212
    def __init__(self, req, context, lastobj):
 
213
        super(XHTMLErrorView, self).__init__(req, context)
 
214
        self.lastobj = lastobj
 
215
 
 
216
    def get_context_ancestry(self, req):
 
217
        return req.publisher.get_ancestors(self.lastobj)
 
218
 
199
219
    def populate(self, req, ctx):
200
220
        ctx['req'] = req
201
221
        ctx['exception'] = self.context
203
223
class XHTMLUnauthorizedView(XHTMLErrorView):
204
224
    template = 'xhtmlunauthorized.html'
205
225
 
206
 
    def __init__(self, req, exception):
207
 
        super(XHTMLUnauthorizedView, self).__init__(req, exception)
 
226
    def __init__(self, req, exception, lastobj):
 
227
        super(XHTMLUnauthorizedView, self).__init__(req, exception, lastobj)
208
228
 
209
229
        if req.user is None:
210
230
            # Not logged in. Redirect to login page.