7
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
8
from ivle.webapp.base.xhtml import XHTMLView
9
from ivle.webapp.errors import NotFound, Forbidden
11
def generate_toc(plugins, req):
13
for plugin in plugins:
14
if hasattr(plugin, 'help'):
15
# Get the dir the plugin resides in
16
plugindir = os.path.dirname(inspect.getmodule(plugin).__file__)
17
add_dict(toc, plugin.help, plugindir)
20
def add_dict(newdict, curdict, plugin):
22
if key not in newdict:
24
if isinstance(curdict[key], dict):
25
add_dict(newdict[key], curdict[key], plugin)
27
newdict[key] = os.path.join(plugin, curdict[key])
30
class HelpView(XHTMLView):
31
"""Shows the help file for the specified path."""
33
template = 'helpview.html'
35
def __init__(self, req, path):
36
self.paths = path.split('/')
38
def authorize(self, req):
39
return req.user is not None
41
def populate(self, req, ctx):
42
self.plugin_styles[Plugin] = ['help.css']
44
helpfile = generate_toc(req.config.plugin_index[ViewPlugin], req)
46
for path in self.paths:
48
helpfile = helpfile[path]
49
except (KeyError, TypeError):
50
# Traversal failed. We 404.
53
if not isinstance(helpfile, basestring):
54
# It's a virtual directory.
57
ctx['helpfile'] = helpfile
60
class HelpToCView(XHTMLView):
61
"""Displays the help Table of Contents."""
65
def authorize(self, req):
66
return req.user is not None
68
def populate(self, req, ctx):
69
ctx['toc'] = generate_toc(req.config.plugin_index[ViewPlugin], req)
72
class Plugin(ViewPlugin, MediaPlugin):
73
"""The plugin for viewing help files."""
76
('+help', HelpToCView),
77
('+help/*path', HelpView)
81
('help', 'Help', 'IVLE help pages', 'help.png', '+help', 100)