~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-07-04 13:40:44 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090704134044-b5n1zaq6l325cc7a
Security (login/logout) done.

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 = []
59
47
 
60
48
    def filter(self, stream, ctx):
61
49
        return stream
104
92
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
105
93
        ctx['app_template'] = app
106
94
        ctx['title_img'] = media_url(req, CorePlugin,
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
 
        if not req.publicmode:
117
 
            for ancestor in ancestry:
118
 
                crumb = crumber.crumb(ancestor)
119
 
                if crumb is None:
120
 
                    continue
121
 
 
122
 
                if hasattr(crumb, 'extra_breadcrumbs_before'):
123
 
                    ctx['breadcrumbs'].extend(crumb.extra_breadcrumbs_before)
124
 
                ctx['breadcrumbs'].append(crumb)
125
 
                if hasattr(crumb, 'extra_breadcrumbs_after'):
126
 
                    ctx['breadcrumbs'].extend(crumb.extra_breadcrumbs_after)
127
 
 
128
 
            # If the view has specified text for a breadcrumb, add one.
129
 
            if self.breadcrumb_text:
130
 
                ctx['breadcrumbs'].append(ViewBreadcrumb(req, self))
131
 
 
132
 
            # Allow the view to add its own fake breadcrumbs.
133
 
            ctx['breadcrumbs'].extend(self.extra_breadcrumbs)
134
 
 
 
95
                                     "images/chrome/title.png")
135
96
        self.populate_headings(req, ctx)
136
97
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
137
98
                                                        'ivle-headings.html'))
163
124
                continue
164
125
 
165
126
            for tab in plugin.tabs:
166
 
                # tab is a tuple: name, title, desc, icon, path, weight, admin
167
 
                # (Admin is optional, defaults to false)
 
127
                # tab is a tuple: name, title, desc, icon, path
168
128
                new_app = {}
169
129
                new_app['this_app'] = hasattr(self, 'tab') \
170
130
                                      and tab[0] == self.tab
178
138
                        ctx['favicon'] = icon_url
179
139
                else:
180
140
                    new_app['has_icon'] = False
181
 
                # The following check is here, so it is AFTER setting the
182
 
                # icon, but BEFORE actually installing the tab in the menu
183
 
                if len(tab) > 6 and tab[6]:
184
 
                    # Admin-only tab
185
 
                    if not (req.user and req.user.admin):
186
 
                        break
187
141
                new_app['path'] = req.make_path(tab[4])
188
142
                new_app['desc'] = tab[2]
189
143
                new_app['name'] = tab[1]
235
189
class XHTMLErrorView(XHTMLView):
236
190
    template = 'xhtmlerror.html'
237
191
 
238
 
    def __init__(self, req, context, lastobj):
239
 
        super(XHTMLErrorView, self).__init__(req, context)
240
 
        self.lastobj = lastobj
241
 
 
242
 
    def get_context_ancestry(self, req):
243
 
        return req.publisher.get_ancestors(self.lastobj)
244
 
 
245
192
    def populate(self, req, ctx):
246
193
        ctx['req'] = req
247
194
        ctx['exception'] = self.context
249
196
class XHTMLUnauthorizedView(XHTMLErrorView):
250
197
    template = 'xhtmlunauthorized.html'
251
198
 
252
 
    def __init__(self, req, exception, lastobj):
253
 
        super(XHTMLUnauthorizedView, self).__init__(req, exception, lastobj)
 
199
    def __init__(self, req, exception):
 
200
        super(XHTMLUnauthorizedView, self).__init__(req, exception)
254
201
 
255
 
        if not req.publicmode and req.user is None:
 
202
        if req.user is None:
256
203
            # Not logged in. Redirect to login page.
257
204
            if req.uri == '/':
258
205
                query_string = ''
261
208
            req.throw_redirect('/+login' + query_string)
262
209
 
263
210
        req.status = 403
264
 
 
265
 
class ViewBreadcrumb(object):
266
 
    def __init__(self, req, context):
267
 
        self.req = req
268
 
        self.context = context
269
 
 
270
 
    @property
271
 
    def text(self):
272
 
        return self.context.breadcrumb_text