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

« back to all changes in this revision

Viewing changes to src/apps/help/__init__.py

  • Committer: mattgiuca
  • Date: 2007-12-17 05:27:38 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:75
apps/help: Now displays a top-level menu of all apps with help documents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
def handle(req):
33
33
    """Handler for the Help application."""
34
34
    (appurl, subpath) = util.split_path(req.path)
35
 
    # app must be valid and have help available
36
 
    if appurl not in conf.apps.app_url:
37
 
        req.throw_error(req.HTTP_NOT_FOUND)
38
 
    app = conf.apps.app_url[appurl]
39
 
    if not app.hashelp:
40
 
        req.throw_error(req.HTTP_NOT_FOUND)
41
 
    # subpath must be empty, for now, as there is only one help file per app
42
 
    if subpath != "":
43
 
        req.throw_error(req.HTTP_NOT_FOUND)
 
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
 
58
    req.write("<h1>Help</h1>\n")
 
59
 
 
60
    # Write a list of links to all apps with help modules
 
61
    req.write("<ul>\n")
 
62
    for (appurl, app) in conf.apps.app_url.items():
 
63
        if app.hashelp:
 
64
            req.write('  <li><a href="%s">%s</a></li>\n'
 
65
                % (os.path.join(util.make_path("help"), appurl), app.name))
 
66
    req.write("</ul>\n")
 
67
 
 
68
def show_help_app(req, app):
 
69
    """Show help for an application."""
44
70
    helpfile = os.path.join(util.make_local_path("apps"), app.dir, "help.html")
45
71
 
46
72
    # Set request attributes