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

« back to all changes in this revision

Viewing changes to src/dispatch/__init__.py

  • Committer: mattgiuca
  • Date: 2007-12-11 12:10:49 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:32
src/dispatch: Added code to fetch and print the list of apps with links.
src/conf/apps: Added another app ("help").

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import os
31
31
import os.path
32
32
import conf
 
33
import conf.apps
 
34
 
 
35
root_dir = conf.root_dir
33
36
 
34
37
def handler(req):
 
38
    """Handles a request which may be to anywhere in the site except media.
 
39
    Intended to be called by mod_python, as a handler.
 
40
 
 
41
    req: An Apache request object.
 
42
    """
35
43
    # TEMP: Dummy (test) handler
36
44
    req.content_type = "text/html"
37
 
    req.write("<html>")
38
 
    req.write("<p>Hello, IVLE!</p>")
39
 
    req.write('<p><img src="' + os.path.join(conf.root_dir,
40
 
        "media/images/mime/dir.png") + '" /> ')
 
45
    req.write("<html>\n")
 
46
    req.write("<p>Hello, IVLE!</p>\n")
 
47
    req.write('<p><img src="' + make_path("media/images/mime/dir.png")
 
48
        + '" /> ')
41
49
    req.write(str(req.uri))
42
 
    req.write("</p></html>")
 
50
    req.write("</p>\n")
 
51
 
 
52
    print_apps_list(req)
 
53
 
 
54
    req.write("</html>")
43
55
    return apache.OK
44
56
 
 
57
def make_path(path):
 
58
    """Given a path relative to the IVLE root, makes the path relative to the
 
59
    site root using conf.root_dir. This path can be used in URLs sent to the
 
60
    client."""
 
61
    return os.path.join(root_dir, path)
 
62
 
 
63
def print_apps_list(file):
 
64
    """Prints all app tabs, as a UL. Prints a list item for each app that has
 
65
    a tab.
 
66
 
 
67
    file: Object with a "write" method - ie. the request object.
 
68
    Reads from: conf
 
69
    """
 
70
    file.write('<ul class="apptabs">\n')
 
71
 
 
72
    for urlname in conf.apps.apps_in_tabs:
 
73
        app = conf.apps.app_url[urlname]
 
74
        file.write('  <li><a href="')
 
75
        file.write(make_path(app.dir))
 
76
        file.write('">')
 
77
        file.write(app.name)
 
78
        file.write('</a></li>\n')
 
79
 
 
80
    file.write('</ul>\n')