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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-01-11 07:10:18 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:185
Integrated the (second) Prototype browser (HTML+CSS but no code) into the main
filebrowser app. Note that this still is non-functional - it looks the same as
the original prototype.
browser: Added the full HTML source (including example rows) into the Python
code. (Note this will be a lot cleaner once example rows are removed).
media: Added "images" directory (copied from the demo). This contains all the
icons needed for the demo.
       browser.css: Pasted the entire CSS from the demo. This styles the
        browser interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# content (the common parts of the HTML pages shared across the entire site).
24
24
# Does not include the login page. See login.py.
25
25
 
26
 
import os.path
27
 
 
28
26
import conf
29
27
import conf.apps
30
28
from common import util
39
37
    # Note the inline JavaScript, which provides the client with constants
40
38
    # derived from the server configuration.
41
39
    if req.title != None:
42
 
        titlepart = req.title + ' - '
 
40
        titlepart = ' - ' + req.title
43
41
    else:
44
42
        titlepart = ''
45
43
    req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
46
44
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
47
45
<html xmlns="http://www.w3.org/1999/xhtml">
48
46
<head>
49
 
  <title>%sIVLE</title>
 
47
  <title>IVLE%s</title>
50
48
  <meta http-equiv="Content-Type" content="%s; charset=utf-8" />
51
 
""" % (titlepart, req.content_type))
52
 
    # Write inline JavaScript which gives the client code access to certain
53
 
    # server-side variables.
54
 
    if req.username:
55
 
        username = repr(req.username)
56
 
    else:
57
 
        username = "null"
58
 
    req.write("""  <script type="text/javascript">
59
 
    root_dir = %s;
60
 
    username = %s;
 
49
  <script type="text/javascript">
 
50
    root_dir = "%s";
61
51
  </script>
62
 
""" % (repr(conf.root_dir), username))
63
 
    iconurl = get_icon_url(req.app)
64
 
    if iconurl:
65
 
        req.write("""  <link rel="shortcut icon" href="%s" />
66
 
""" % iconurl)
67
 
    req.write("""  <link rel="stylesheet" type="text/css" href="%s" />
68
 
""" % util.make_path('media/common/ivle.css'))
 
52
  <link rel="stylesheet" type="text/css" href="%s" />
 
53
""" % (titlepart, req.content_type,
 
54
        repr(conf.root_dir)[1:-1],
 
55
        util.make_path('media/common/ivle.css')))
69
56
 
70
57
    # Write any app-specific style and script links
71
58
    for style in req.styles:
79
66
 
80
67
    # Open the body element and write a bunch of stuff there (the header)
81
68
    req.write("""<body>
82
 
<div id="ivleheader">
83
 
  <h1>IVLE</h1>
84
 
  <h2>Informatics Virtual Learning Environment</h2>
 
69
<h1>IVLE - Informatics Virtual Learning Environment</h1>
85
70
""")
86
71
 
87
72
    if req.username:
88
 
        req.write('  <p class="userhello">Welcome, <span '
89
 
            'class="username">%s</span> |\n'
90
 
            '    <a href="%s">Help</a> |\n'
91
 
            '    <a href="%s">Logout</a>\n'
92
 
            '  </p>\n' %
93
 
            (req.username, get_help_url(req), util.make_path('logout')))
 
73
        req.write("""<p>Hello, %s. <a href="%s">Logout</a></p>\n""" %
 
74
            (req.username, util.make_path('logout')))
94
75
    else:
95
 
        req.write('  <p class="userhello">Not logged in.</p>')
 
76
        req.write("<p>Not logged in.</p>")
96
77
 
97
78
    # If the "debuginfo" app is installed, display a warning to the admin to
98
79
    # make sure it is removed in production.
99
80
    if "debuginfo" in conf.apps.app_url:
100
 
        req.write("  <p><small>Warning: debuginfo is enabled. Remove this "
101
 
            "app from conf.apps.app_url when placed into production."
102
 
            "</small></p>\n")
 
81
        req.write("<p>Warning: debuginfo is enabled. Remove this app from "
 
82
            "conf.apps.app_url when placed into production.</p>\n")
103
83
 
104
 
    if req.username:
105
 
        # Only print app tabs if logged in
106
 
        print_apps_list(req, req.app)
107
 
    req.write('</div>\n<div id="ivlebody">\n')
 
84
    print_apps_list(req)
108
85
 
109
86
def write_html_foot(req):
110
87
    """Writes the HTML footer, given a request object.
111
88
 
112
89
    req: An IVLE request object. Written to.
113
90
    """
114
 
    req.write("</div>\n</body>\n</html>\n")
115
 
 
116
 
def get_help_url(req):
117
 
    """Gets the help URL most relevant to this page, to place as the
118
 
    "help" link at the top of the page."""
119
 
    if req.app == 'help':
120
 
        # We're already in help. Link to the exact current page
121
 
        # instead of the generic help page.
122
 
        return req.uri
123
 
    if conf.apps.app_url[req.app].hashelp:
124
 
        help_path = os.path.join('help', req.app)
125
 
    else:
126
 
        help_path = 'help'
127
 
    return util.make_path(help_path)
128
 
 
129
 
def get_icon_url(appurl, small=False):
130
 
    """Given an app's url name, gets the URL of the icon image for this app,
131
 
    relative to the site root. Returns None if the app has no icon."""
132
 
    if appurl is None: return None
133
 
    app = conf.apps.app_url[appurl]
134
 
    if small:
135
 
        icon_dir = conf.apps.app_icon_dir_small
136
 
    else:
137
 
        icon_dir = conf.apps.app_icon_dir
138
 
    if app.icon is None: return None
139
 
    return util.make_path(os.path.join(icon_dir, app.icon))
140
 
 
141
 
def print_apps_list(file, thisapp):
 
91
    req.write("</body>\n</html>\n")
 
92
 
 
93
def print_apps_list(file):
142
94
    """Prints all app tabs, as a UL. Prints a list item for each app that has
143
95
    a tab.
144
96
 
145
97
    file: Object with a "write" method - ie. the request object.
146
98
    Reads from: conf
147
99
    """
148
 
    file.write('  <ul id="apptabs">\n')
 
100
    file.write('<ul class="apptabs">\n')
149
101
 
150
102
    for urlname in conf.apps.apps_in_tabs:
151
103
        app = conf.apps.app_url[urlname]
152
 
        if urlname == thisapp:
153
 
            li_attr = ' class="thisapp"'
154
 
        else:
155
 
            li_attr = ''
156
 
        file.write('    <li%s>' % li_attr)
157
 
        if app.icon:
158
 
            file.write('<img src="%s" alt="" /> ' % get_icon_url(urlname))
159
 
        file.write('<a href="%s">%s</a></li>\n'
 
104
        file.write('  <li><a href="%s">%s</a></li>\n'
160
105
            % (util.make_path(urlname), app.name))
161
106
 
162
 
    file.write('  </ul>\n')
 
107
    file.write('</ul>\n')