~azzar1/unity/add-show-desktop-key

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
import os
458 by mattgiuca
Added "tos" as an app. This app simply displays the Terms of Service
26
import copy
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
27
28
from ivle import util
29
import ivle.conf
93 by mattgiuca
New directory hierarchy.
30
31
# TODO: Nicer 404 errors
32
33
def handle(req):
34
    """Handler for the Help application."""
35
    (appurl, subpath) = util.split_path(req.path)
36
37
    if appurl is None:
38
        show_help_menu(req)
39
    else:
40
        # app must be valid and have help available
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
41
        if appurl not in ivle.conf.apps.app_url:
93 by mattgiuca
New directory hierarchy.
42
            req.throw_error(req.HTTP_NOT_FOUND)
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
43
        app = ivle.conf.apps.app_url[appurl]
93 by mattgiuca
New directory hierarchy.
44
        if not app.hashelp:
45
            req.throw_error(req.HTTP_NOT_FOUND)
46
        # subpath must be empty, for now, as there is only one help file per app
47
        if subpath != "":
48
            req.throw_error(req.HTTP_NOT_FOUND)
49
        show_help_app(req, app)
50
51
def show_help_menu(req):
52
    """Show the help menu."""
53
54
    # Set request attributes
55
    req.content_type = "text/html"
56
    req.write_html_head_foot = True
57
58
    # Start writing data
345 by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none).
59
    req.write('<div id="ivle_padding">\n')
93 by mattgiuca
New directory hierarchy.
60
    req.write("<h1>Help</h1>\n")
61
62
    # Write a list of links to all apps with help modules
63
    req.write("<ul>\n")
458 by mattgiuca
Added "tos" as an app. This app simply displays the Terms of Service
64
    # Tab apps, in order of tabs
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
65
    for appurl in ivle.conf.apps.apps_in_tabs:
66
        app = ivle.conf.apps.app_url[appurl]
93 by mattgiuca
New directory hierarchy.
67
        if app.hashelp:
68
            req.write('  <li><a href="%s">%s</a></li>\n'
69
                % (os.path.join(util.make_path("help"), appurl), app.name))
458 by mattgiuca
Added "tos" as an app. This app simply displays the Terms of Service
70
    # Terms of Service
71
    req.write('  <li><a href="%s">Terms of Service</a></li>\n'
72
        % (util.make_path("tos")))
93 by mattgiuca
New directory hierarchy.
73
    req.write("</ul>\n")
345 by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none).
74
    req.write('</div>\n')
93 by mattgiuca
New directory hierarchy.
75
76
def show_help_app(req, app):
77
    """Show help for an application."""
78
    helpfile = os.path.join(util.make_local_path("apps"), app.dir, "help.html")
79
80
    # Set request attributes
81
    req.content_type = "text/html"
82
    req.write_html_head_foot = True
731 by dcoles
Help: Wrote a small help document for the console app. Now one less glaring
83
    req.styles = ["media/help/help.css"]
93 by mattgiuca
New directory hierarchy.
84
85
    # Start writing data
345 by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none).
86
    req.write('<div id="ivle_padding">\n')
93 by mattgiuca
New directory hierarchy.
87
    req.write("<h1>Help - %s</h1>\n" % app.name)
88
89
    # Print out the contents of the HTML help file
90
    req.sendfile(helpfile)
345 by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none).
91
    req.write('</div>\n')