~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-02-24 06:01:52 UTC
  • mfrom: (1099.5.5 new-dispatch)
  • mto: This revision was merged to the branch mainline in revision 1119.
  • Revision ID: grantw@unimelb.edu.au-20090224060152-136r6lj6zc2eaexp
Merge my console and tutorial changes.

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
import ivle.conf
 
32
import ivle.util
31
33
 
32
34
class XHTMLView(BaseView):
33
35
    """
37
39
    """
38
40
 
39
41
    template = 'template.html'
40
 
 
41
42
    plugin_scripts = {}
42
43
    plugin_styles = {}
43
 
    scripts_init = []
44
 
 
45
44
    allow_overlays = True
46
45
    overlay_blacklist = []
47
46
 
49
48
        for key in kwargs:
50
49
            setattr(self, key, kwargs[key])
51
50
 
52
 
    def filter(self, stream, ctx):
53
 
        return stream
54
 
 
55
51
    def render(self, req):
56
52
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
57
53
 
65
61
                        inspect.getmodule(self).__file__), self.template) 
66
62
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
67
63
        tmpl = loader.load(app_template)
68
 
        app = self.filter(tmpl.generate(viewctx), viewctx)
 
64
        app = tmpl.generate(viewctx)
69
65
 
70
 
        view_scripts = []
71
66
        for plugin in self.plugin_scripts:
72
67
            for path in self.plugin_scripts[plugin]:
73
 
                view_scripts.append(media_url(req, plugin, path))
 
68
                req.scripts.append(media_url(req, plugin, path))
74
69
 
75
 
        view_styles = []
76
70
        for plugin in self.plugin_styles:
77
71
            for path in self.plugin_styles[plugin]:
78
 
                view_styles.append(media_url(req, plugin, path))
 
72
                req.styles.append(media_url(req, plugin, path))
79
73
 
80
74
        # Global template
81
75
        ctx = genshi.template.Context()
82
 
 
83
 
        overlay_bits = self.render_overlays(req) if req.user else [[]]*4
84
 
        ctx['overlays'] = overlay_bits[0]
 
76
        # XXX: Leave this here!! (Before req.styles is read)
 
77
        ctx['overlays'] = self.render_overlays(req) if req.user else []
85
78
 
86
79
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
87
 
        ctx['styles'] += view_styles
88
 
        ctx['styles'] += overlay_bits[1]
 
80
        ctx['styles'] += req.styles
89
81
 
90
82
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
91
83
                           ('util.js', 'json2.js', 'md5.js')]
92
 
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
93
 
        ctx['scripts'] += view_scripts
94
 
        ctx['scripts'] += overlay_bits[2]
 
84
        ctx['scripts'] += req.scripts
95
85
 
96
 
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
 
86
        ctx['scripts_init'] = req.scripts_init
97
87
        ctx['app_template'] = app
98
 
        ctx['title_img'] = media_url(req, CorePlugin,
99
 
                                     "images/chrome/title.png")
100
88
        self.populate_headings(req, ctx)
101
89
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
102
90
                                                        'ivle-headings.html'))
107
95
 
108
96
    def populate_headings(self, req, ctx):
109
97
        ctx['favicon'] = None
110
 
        ctx['root_dir'] = req.config['urls']['root']
111
 
        ctx['public_host'] = req.config['urls']['public_host']
112
 
        ctx['svn_base'] = req.config['urls']['svn_addr']
 
98
        ctx['root_dir'] = ivle.conf.root_dir
 
99
        ctx['public_host'] = ivle.conf.public_host
113
100
        ctx['write_javascript_settings'] = req.write_javascript_settings
114
101
        if req.user:
115
102
            ctx['login'] = req.user.login
130
117
            for tab in plugin.tabs:
131
118
                # tab is a tuple: name, title, desc, icon, path
132
119
                new_app = {}
133
 
                new_app['this_app'] = hasattr(self, 'tab') \
134
 
                                      and tab[0] == self.tab
 
120
                new_app['this_app'] = hasattr(self, 'appname') \
 
121
                                      and tab[0] == self.appname
135
122
 
136
123
                # Icon name
137
124
                if tab[3] is not None:
142
129
                        ctx['favicon'] = icon_url
143
130
                else:
144
131
                    new_app['has_icon'] = False
145
 
                new_app['path'] = req.make_path(tab[4])
 
132
                new_app['path'] = ivle.util.make_path(tab[4])
146
133
                new_app['desc'] = tab[2]
147
134
                new_app['name'] = tab[1]
148
135
                new_app['weight'] = tab[5]
157
144
        scripts_init.
158
145
        """
159
146
        overlays = []
160
 
        styles = []
161
 
        scripts = []
162
 
        scripts_init = []
163
147
        if not self.allow_overlays:
164
 
            return (overlays, styles, scripts, scripts_init)
 
148
            return overlays
165
149
 
166
150
        for plugin in req.config.plugin_index[OverlayPlugin]:
167
151
            for overclass in plugin.overlays:
171
155
                #TODO: Re-factor this to look nicer
172
156
                for mplugin in overlay.plugin_scripts:
173
157
                    for path in overlay.plugin_scripts[mplugin]:
174
 
                        scripts.append(media_url(req, mplugin, path))
 
158
                        req.scripts.append(media_url(req, mplugin, path))
175
159
 
176
160
                for mplugin in overlay.plugin_styles:
177
161
                    for path in overlay.plugin_styles[mplugin]:
178
 
                        styles.append(media_url(req, mplugin, path))
 
162
                        req.styles.append(media_url(req, mplugin, path))
179
163
 
180
 
                scripts_init += overlay.plugin_scripts_init
 
164
                req.scripts_init += overlay.plugin_scripts_init
181
165
 
182
166
                overlays.append(overlay.render(req))
183
 
        return (overlays, styles, scripts, scripts_init)
 
167
        return overlays
184
168
 
185
169
    @classmethod
186
170
    def get_error_view(cls, e):