24
24
import genshi.template
26
26
from ivle.webapp.media import media_url
27
from ivle.webapp.core import Plugin as CorePlugin
27
28
from ivle.webapp.base.views import BaseView
28
29
from ivle.webapp.base.plugins import ViewPlugin, OverlayPlugin
29
30
from ivle.webapp.errors import HTTPError, Unauthorized
33
32
class XHTMLView(BaseView):
59
64
app_template = os.path.join(os.path.dirname(
60
65
inspect.getmodule(self).__file__), self.template)
61
req.write_html_head_foot = False
62
66
loader = genshi.template.TemplateLoader(".", auto_reload=True)
63
67
tmpl = loader.load(app_template)
64
app = tmpl.generate(viewctx)
68
app = self.filter(tmpl.generate(viewctx), viewctx)
66
71
for plugin in self.plugin_scripts:
67
72
for path in self.plugin_scripts[plugin]:
68
req.scripts.append(media_url(req, plugin, path))
73
view_scripts.append(media_url(req, plugin, path))
70
76
for plugin in self.plugin_styles:
71
77
for path in self.plugin_styles[plugin]:
72
req.styles.append(media_url(req, plugin, path))
78
view_styles.append(media_url(req, plugin, path))
75
81
ctx = genshi.template.Context()
76
# XXX: Leave this here!! (Before req.styles is read)
77
ctx['overlays'] = self.render_overlays(req)
78
ctx['app_styles'] = req.styles
79
ctx['scripts'] = req.scripts
80
ctx['scripts_init'] = req.scripts_init
83
overlay_bits = self.render_overlays(req) if req.user else [[]]*4
84
ctx['overlays'] = overlay_bits[0]
86
ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
87
ctx['styles'] += view_styles
88
ctx['styles'] += overlay_bits[1]
90
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]
96
ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
81
97
ctx['app_template'] = app
98
ctx['title_img'] = media_url(req, CorePlugin,
99
"images/chrome/title.png")
82
100
self.populate_headings(req, ctx)
83
101
tmpl = loader.load(os.path.join(os.path.dirname(__file__),
84
102
'ivle-headings.html'))
90
108
def populate_headings(self, req, ctx):
91
109
ctx['favicon'] = None
92
ctx['root_dir'] = ivle.conf.root_dir
93
ctx['public_host'] = ivle.conf.public_host
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']
94
113
ctx['write_javascript_settings'] = req.write_javascript_settings
96
115
ctx['login'] = req.user.login
104
123
ctx['help_path'] = self.help
106
125
ctx['apps_in_tabs'] = []
107
for plugin in req.plugin_index[ViewPlugin]:
126
for plugin in req.config.plugin_index[ViewPlugin]:
108
127
if not hasattr(plugin, 'tabs'):
111
130
for tab in plugin.tabs:
112
131
# tab is a tuple: name, title, desc, icon, path
114
new_app['this_app'] = hasattr(self, 'appname') \
115
and tab[0] == self.appname
133
new_app['this_app'] = hasattr(self, 'tab') \
134
and tab[0] == self.tab
118
137
if tab[3] is not None:
141
163
if not self.allow_overlays:
164
return (overlays, styles, scripts, scripts_init)
144
for plugin in req.plugin_index[OverlayPlugin]:
166
for plugin in req.config.plugin_index[OverlayPlugin]:
145
167
for overclass in plugin.overlays:
146
168
if overclass in self.overlay_blacklist:
149
171
#TODO: Re-factor this to look nicer
150
172
for mplugin in overlay.plugin_scripts:
151
173
for path in overlay.plugin_scripts[mplugin]:
152
req.scripts.append(media_url(req, mplugin, path))
174
scripts.append(media_url(req, mplugin, path))
154
176
for mplugin in overlay.plugin_styles:
155
177
for path in overlay.plugin_styles[mplugin]:
156
req.styles.append(media_url(req, mplugin, path))
178
styles.append(media_url(req, mplugin, path))
158
req.scripts_init += overlay.plugin_scripts_init
180
scripts_init += overlay.plugin_scripts_init
160
182
overlays.append(overlay.render(req))
183
return (overlays, styles, scripts, scripts_init)
164
186
def get_error_view(cls, e):