40
41
template = 'template.html'
42
42
plugin_scripts = {}
46
44
allow_overlays = True
47
45
overlay_blacklist = []
49
def filter(self, stream, ctx):
47
def __init__(self, req, **kwargs):
49
setattr(self, key, kwargs[key])
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)
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))
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))
78
75
ctx = genshi.template.Context()
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 []
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
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
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")
98
ctx['ancestry'] = req.router.get_ancestors(self.context)
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'))
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
118
104
ctx['login'] = req.user.login
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))
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))
183
scripts_init += overlay.plugin_scripts_init
166
req.scripts_init += overlay.plugin_scripts_init
185
168
overlays.append(overlay.render(req))
186
return (overlays, styles, scripts, scripts_init)
189
172
def get_error_view(cls, e):
196
179
class XHTMLErrorView(XHTMLView):
197
180
template = 'xhtmlerror.html'
182
def __init__(self, req, exception):
183
self.context = exception
199
185
def populate(self, req, ctx):
201
186
ctx['exception'] = self.context
203
188
class XHTMLUnauthorizedView(XHTMLErrorView):