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

« back to all changes in this revision

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

  • Committer: Nick Chadwick
  • Date: 2009-03-09 00:15:21 UTC
  • mfrom: (1099.6.4 new-dispatch)
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090309001521-dffcygyuyvs2cap0
finished the exercise-ui. It is now ready to be merged with trunk.

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
 
                           ('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]
 
83
                           ('util.js', 'json2.js', 'md5.js', 'jquery.js')]
 
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
88
        ctx['title_img'] = media_url(req, CorePlugin,
99
89
                                     "images/chrome/title.png")
107
97
 
108
98
    def populate_headings(self, req, ctx):
109
99
        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']
 
100
        ctx['root_dir'] = ivle.conf.root_dir
 
101
        ctx['public_host'] = ivle.conf.public_host
113
102
        ctx['write_javascript_settings'] = req.write_javascript_settings
114
103
        if req.user:
115
104
            ctx['login'] = req.user.login
142
131
                        ctx['favicon'] = icon_url
143
132
                else:
144
133
                    new_app['has_icon'] = False
145
 
                new_app['path'] = req.make_path(tab[4])
 
134
                new_app['path'] = ivle.util.make_path(tab[4])
146
135
                new_app['desc'] = tab[2]
147
136
                new_app['name'] = tab[1]
148
137
                new_app['weight'] = tab[5]
157
146
        scripts_init.
158
147
        """
159
148
        overlays = []
160
 
        styles = []
161
 
        scripts = []
162
 
        scripts_init = []
163
149
        if not self.allow_overlays:
164
 
            return (overlays, styles, scripts, scripts_init)
 
150
            return overlays
165
151
 
166
152
        for plugin in req.config.plugin_index[OverlayPlugin]:
167
153
            for overclass in plugin.overlays:
171
157
                #TODO: Re-factor this to look nicer
172
158
                for mplugin in overlay.plugin_scripts:
173
159
                    for path in overlay.plugin_scripts[mplugin]:
174
 
                        scripts.append(media_url(req, mplugin, path))
 
160
                        req.scripts.append(media_url(req, mplugin, path))
175
161
 
176
162
                for mplugin in overlay.plugin_styles:
177
163
                    for path in overlay.plugin_styles[mplugin]:
178
 
                        styles.append(media_url(req, mplugin, path))
 
164
                        req.styles.append(media_url(req, mplugin, path))
179
165
 
180
 
                scripts_init += overlay.plugin_scripts_init
 
166
                req.scripts_init += overlay.plugin_scripts_init
181
167
 
182
168
                overlays.append(overlay.render(req))
183
 
        return (overlays, styles, scripts, scripts_init)
 
169
        return overlays
184
170
 
185
171
    @classmethod
186
172
    def get_error_view(cls, e):