39
41
template = 'template.html'
41
42
plugin_scripts = {}
46
44
overlay_blacklist = []
48
46
def __init__(self, req, **kwargs):
50
48
setattr(self, key, kwargs[key])
52
def filter(self, stream, ctx):
55
50
def render(self, req):
56
51
req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
64
59
app_template = os.path.join(os.path.dirname(
65
60
inspect.getmodule(self).__file__), self.template)
61
req.write_html_head_foot = False
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)
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))
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))
81
75
ctx = genshi.template.Context()
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)
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
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
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'))
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
115
102
ctx['login'] = req.user.login
123
110
ctx['help_path'] = self.help
125
112
ctx['apps_in_tabs'] = []
126
for plugin in req.config.plugin_index[ViewPlugin]:
113
for plugin in req.plugin_index[ViewPlugin]:
127
114
if not hasattr(plugin, 'tabs'):
130
117
for tab in plugin.tabs:
131
118
# tab is a tuple: name, title, desc, icon, path
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
137
124
if tab[3] is not None:
163
if not self.allow_overlays:
164
return (overlays, styles, scripts, scripts_init)
166
for plugin in req.config.plugin_index[OverlayPlugin]:
147
for plugin in req.plugin_index[OverlayPlugin]:
167
148
for overclass in plugin.overlays:
168
149
if overclass in self.overlay_blacklist:
171
152
#TODO: Re-factor this to look nicer
172
153
for mplugin in overlay.plugin_scripts:
173
154
for path in overlay.plugin_scripts[mplugin]:
174
scripts.append(media_url(req, mplugin, path))
155
req.scripts.append(media_url(req, mplugin, path))
176
157
for mplugin in overlay.plugin_styles:
177
158
for path in overlay.plugin_styles[mplugin]:
178
styles.append(media_url(req, mplugin, path))
159
req.styles.append(media_url(req, mplugin, path))
180
scripts_init += overlay.plugin_scripts_init
161
req.scripts_init += overlay.plugin_scripts_init
182
163
overlays.append(overlay.render(req))
183
return (overlays, styles, scripts, scripts_init)
186
167
def get_error_view(cls, e):