93
by mattgiuca
New directory hierarchy. |
1 |
# IVLE
|
2 |
# Copyright (C) 2007-2008 The University of Melbourne
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
||
18 |
# App: help
|
|
19 |
# Author: Matt Giuca
|
|
20 |
# Date: 12/12/2007
|
|
21 |
||
22 |
# This is an IVLE application.
|
|
23 |
# A sample / testing application for IVLE.
|
|
24 |
||
25 |
from common import util |
|
26 |
import os |
|
27 |
import conf |
|
28 |
from conf import apps |
|
29 |
||
30 |
# TODO: Nicer 404 errors
|
|
31 |
||
32 |
def handle(req): |
|
33 |
"""Handler for the Help application."""
|
|
34 |
(appurl, subpath) = util.split_path(req.path) |
|
35 |
||
36 |
if appurl is None: |
|
37 |
show_help_menu(req) |
|
38 |
else: |
|
39 |
# app must be valid and have help available
|
|
40 |
if appurl not in conf.apps.app_url: |
|
41 |
req.throw_error(req.HTTP_NOT_FOUND) |
|
42 |
app = conf.apps.app_url[appurl] |
|
43 |
if not app.hashelp: |
|
44 |
req.throw_error(req.HTTP_NOT_FOUND) |
|
45 |
# subpath must be empty, for now, as there is only one help file per app
|
|
46 |
if subpath != "": |
|
47 |
req.throw_error(req.HTTP_NOT_FOUND) |
|
48 |
show_help_app(req, app) |
|
49 |
||
50 |
def show_help_menu(req): |
|
51 |
"""Show the help menu."""
|
|
52 |
||
53 |
# Set request attributes
|
|
54 |
req.content_type = "text/html" |
|
55 |
req.write_html_head_foot = True |
|
56 |
||
57 |
# Start writing data
|
|
345
by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none). |
58 |
req.write('<div id="ivle_padding">\n') |
93
by mattgiuca
New directory hierarchy. |
59 |
req.write("<h1>Help</h1>\n") |
60 |
||
61 |
# Write a list of links to all apps with help modules
|
|
62 |
req.write("<ul>\n") |
|
63 |
for (appurl, app) in conf.apps.app_url.items(): |
|
64 |
if app.hashelp: |
|
65 |
req.write(' <li><a href="%s">%s</a></li>\n' |
|
66 |
% (os.path.join(util.make_path("help"), appurl), app.name)) |
|
67 |
req.write("</ul>\n") |
|
345
by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none). |
68 |
req.write('</div>\n') |
93
by mattgiuca
New directory hierarchy. |
69 |
|
70 |
def show_help_app(req, app): |
|
71 |
"""Show help for an application."""
|
|
72 |
helpfile = os.path.join(util.make_local_path("apps"), app.dir, "help.html") |
|
73 |
||
74 |
# Set request attributes
|
|
75 |
req.content_type = "text/html" |
|
76 |
req.write_html_head_foot = True |
|
77 |
||
78 |
# Start writing data
|
|
345
by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none). |
79 |
req.write('<div id="ivle_padding">\n') |
93
by mattgiuca
New directory hierarchy. |
80 |
req.write("<h1>Help - %s</h1>\n" % app.name) |
81 |
||
82 |
# Print out the contents of the HTML help file
|
|
83 |
req.sendfile(helpfile) |
|
345
by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none). |
84 |
req.write('</div>\n') |