~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-05 08:57:26 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-20090705085726-w5aqfe833k3s3c0u
Add a breadcrumb generator (indexes plugins on what breadcrumbs they have).

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
32
 
32
33
class XHTMLView(BaseView):
33
34
    """
37
38
    """
38
39
 
39
40
    template = 'template.html'
 
41
 
40
42
    plugin_scripts = {}
41
43
    plugin_styles = {}
 
44
    scripts_init = []
 
45
 
42
46
    allow_overlays = True
43
47
    overlay_blacklist = []
44
48
 
45
 
    def __init__(self, req, **kwargs):
46
 
        for key in kwargs:
47
 
            setattr(self, key, kwargs[key])
48
 
 
49
49
    def filter(self, stream, ctx):
50
50
        return stream
51
51
 
64
64
        tmpl = loader.load(app_template)
65
65
        app = self.filter(tmpl.generate(viewctx), viewctx)
66
66
 
 
67
        view_scripts = []
67
68
        for plugin in self.plugin_scripts:
68
69
            for path in self.plugin_scripts[plugin]:
69
 
                req.scripts.append(media_url(req, plugin, path))
 
70
                view_scripts.append(media_url(req, plugin, path))
70
71
 
 
72
        view_styles = []
71
73
        for plugin in self.plugin_styles:
72
74
            for path in self.plugin_styles[plugin]:
73
 
                req.styles.append(media_url(req, plugin, path))
 
75
                view_styles.append(media_url(req, plugin, path))
74
76
 
75
77
        # Global template
76
78
        ctx = genshi.template.Context()
77
 
        # XXX: Leave this here!! (Before req.styles is read)
78
 
        ctx['overlays'] = self.render_overlays(req) if req.user else []
 
79
 
 
80
        overlay_bits = self.render_overlays(req) if req.user else [[]]*4
 
81
        ctx['overlays'] = overlay_bits[0]
79
82
 
80
83
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
81
 
        ctx['styles'] += req.styles
 
84
        ctx['styles'] += view_styles
 
85
        ctx['styles'] += overlay_bits[1]
82
86
 
83
87
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
84
88
                           ('util.js', 'json2.js', 'md5.js')]
85
89
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
86
 
        ctx['scripts'] += req.scripts
 
90
        ctx['scripts'] += view_scripts
 
91
        ctx['scripts'] += overlay_bits[2]
87
92
 
88
 
        ctx['scripts_init'] = req.scripts_init
 
93
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
89
94
        ctx['app_template'] = app
90
95
        ctx['title_img'] = media_url(req, CorePlugin,
91
 
                                     "images/chrome/title.png")
 
96
                                     "images/chrome/root-breadcrumb.png")
 
97
        try:
 
98
            ctx['ancestry'] = req.router.get_ancestors(self.context)
 
99
        except NoPath:
 
100
            ctx['ancestry'] = []
 
101
        ctx['breadcrumb_text'] = lambda x: x # TODO: Do it properly.
 
102
        ctx['url'] = req.router.generate
92
103
        self.populate_headings(req, ctx)
93
104
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
94
105
                                                        'ivle-headings.html'))
149
160
        scripts_init.
150
161
        """
151
162
        overlays = []
 
163
        styles = []
 
164
        scripts = []
 
165
        scripts_init = []
152
166
        if not self.allow_overlays:
153
 
            return overlays
 
167
            return (overlays, styles, scripts, scripts_init)
154
168
 
155
169
        for plugin in req.config.plugin_index[OverlayPlugin]:
156
170
            for overclass in plugin.overlays:
160
174
                #TODO: Re-factor this to look nicer
161
175
                for mplugin in overlay.plugin_scripts:
162
176
                    for path in overlay.plugin_scripts[mplugin]:
163
 
                        req.scripts.append(media_url(req, mplugin, path))
 
177
                        scripts.append(media_url(req, mplugin, path))
164
178
 
165
179
                for mplugin in overlay.plugin_styles:
166
180
                    for path in overlay.plugin_styles[mplugin]:
167
 
                        req.styles.append(media_url(req, mplugin, path))
 
181
                        styles.append(media_url(req, mplugin, path))
168
182
 
169
 
                req.scripts_init += overlay.plugin_scripts_init
 
183
                scripts_init += overlay.plugin_scripts_init
170
184
 
171
185
                overlays.append(overlay.render(req))
172
 
        return overlays
 
186
        return (overlays, styles, scripts, scripts_init)
173
187
 
174
188
    @classmethod
175
189
    def get_error_view(cls, e):
182
196
class XHTMLErrorView(XHTMLView):
183
197
    template = 'xhtmlerror.html'
184
198
 
185
 
    def __init__(self, req, exception):
186
 
        self.context = exception
187
 
 
188
199
    def populate(self, req, ctx):
 
200
        ctx['req'] = req
189
201
        ctx['exception'] = self.context
190
202
 
191
203
class XHTMLUnauthorizedView(XHTMLErrorView):