~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-03 01:48:48 UTC
  • mto: (1099.1.227 exercise-ui)
  • mto: This revision was merged to the branch mainline in revision 1162.
  • Revision ID: chadnickbok@gmail.com-20090303014848-dyurvmtmbneohd7f
Modified the setup script to include '.txt' files.

This allows the automatic inclusion of definitions.txt from the rst
code, as it is needed by all worksheets.

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
import ivle.conf
 
32
import ivle.util
32
33
 
33
34
class XHTMLView(BaseView):
34
35
    """
38
39
    """
39
40
 
40
41
    template = 'template.html'
41
 
 
42
42
    plugin_scripts = {}
43
43
    plugin_styles = {}
44
 
    scripts_init = []
45
 
 
46
44
    allow_overlays = True
47
45
    overlay_blacklist = []
48
46
 
49
 
    def filter(self, stream, ctx):
50
 
        return stream
 
47
    def __init__(self, req, **kwargs):
 
48
        for key in kwargs:
 
49
            setattr(self, key, kwargs[key])
51
50
 
52
51
    def render(self, req):
53
52
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
62
61
                        inspect.getmodule(self).__file__), self.template) 
63
62
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
64
63
        tmpl = loader.load(app_template)
65
 
        app = self.filter(tmpl.generate(viewctx), viewctx)
 
64
        app = tmpl.generate(viewctx)
66
65
 
67
 
        view_scripts = []
68
66
        for plugin in self.plugin_scripts:
69
67
            for path in self.plugin_scripts[plugin]:
70
 
                view_scripts.append(media_url(req, plugin, path))
 
68
                req.scripts.append(media_url(req, plugin, path))
71
69
 
72
 
        view_styles = []
73
70
        for plugin in self.plugin_styles:
74
71
            for path in self.plugin_styles[plugin]:
75
 
                view_styles.append(media_url(req, plugin, path))
 
72
                req.styles.append(media_url(req, plugin, path))
76
73
 
77
74
        # Global template
78
75
        ctx = genshi.template.Context()
79
 
 
80
 
        overlay_bits = self.render_overlays(req) if req.user else [[]]*4
81
 
        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 []
82
78
 
83
79
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
84
 
        ctx['styles'] += view_styles
85
 
        ctx['styles'] += overlay_bits[1]
 
80
        ctx['styles'] += req.styles
86
81
 
87
82
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
88
 
                           ('util.js', 'json2.js', 'md5.js')]
89
 
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
90
 
        ctx['scripts'] += view_scripts
91
 
        ctx['scripts'] += overlay_bits[2]
 
83
                           ('util.js', 'json2.js', 'md5.js', 'jquery.js')]
 
84
        ctx['scripts'] += req.scripts
92
85
 
93
 
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
 
86
        ctx['scripts_init'] = req.scripts_init
94
87
        ctx['app_template'] = app
95
88
        ctx['title_img'] = media_url(req, CorePlugin,
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
 
89
                                     "images/chrome/title.png")
103
90
        self.populate_headings(req, ctx)
104
91
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
105
92
                                                        'ivle-headings.html'))
110
97
 
111
98
    def populate_headings(self, req, ctx):
112
99
        ctx['favicon'] = None
113
 
        ctx['root_dir'] = req.config['urls']['root']
114
 
        ctx['public_host'] = req.config['urls']['public_host']
115
 
        ctx['svn_base'] = req.config['urls']['svn_addr']
 
100
        ctx['root_dir'] = ivle.conf.root_dir
 
101
        ctx['public_host'] = ivle.conf.public_host
116
102
        ctx['write_javascript_settings'] = req.write_javascript_settings
117
103
        if req.user:
118
104
            ctx['login'] = req.user.login
145
131
                        ctx['favicon'] = icon_url
146
132
                else:
147
133
                    new_app['has_icon'] = False
148
 
                new_app['path'] = req.make_path(tab[4])
 
134
                new_app['path'] = ivle.util.make_path(tab[4])
149
135
                new_app['desc'] = tab[2]
150
136
                new_app['name'] = tab[1]
151
137
                new_app['weight'] = tab[5]
160
146
        scripts_init.
161
147
        """
162
148
        overlays = []
163
 
        styles = []
164
 
        scripts = []
165
 
        scripts_init = []
166
149
        if not self.allow_overlays:
167
 
            return (overlays, styles, scripts, scripts_init)
 
150
            return overlays
168
151
 
169
152
        for plugin in req.config.plugin_index[OverlayPlugin]:
170
153
            for overclass in plugin.overlays:
174
157
                #TODO: Re-factor this to look nicer
175
158
                for mplugin in overlay.plugin_scripts:
176
159
                    for path in overlay.plugin_scripts[mplugin]:
177
 
                        scripts.append(media_url(req, mplugin, path))
 
160
                        req.scripts.append(media_url(req, mplugin, path))
178
161
 
179
162
                for mplugin in overlay.plugin_styles:
180
163
                    for path in overlay.plugin_styles[mplugin]:
181
 
                        styles.append(media_url(req, mplugin, path))
 
164
                        req.styles.append(media_url(req, mplugin, path))
182
165
 
183
 
                scripts_init += overlay.plugin_scripts_init
 
166
                req.scripts_init += overlay.plugin_scripts_init
184
167
 
185
168
                overlays.append(overlay.render(req))
186
 
        return (overlays, styles, scripts, scripts_init)
 
169
        return overlays
187
170
 
188
171
    @classmethod
189
172
    def get_error_view(cls, e):
196
179
class XHTMLErrorView(XHTMLView):
197
180
    template = 'xhtmlerror.html'
198
181
 
 
182
    def __init__(self, req, exception):
 
183
        self.context = exception
 
184
 
199
185
    def populate(self, req, ctx):
200
 
        ctx['req'] = req
201
186
        ctx['exception'] = self.context
202
187
 
203
188
class XHTMLUnauthorizedView(XHTMLErrorView):