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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-07-15 07:19:34 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:875
Added "migrations" directory, which contains incremental database update
    scripts.
Updated users.sql, uniqueness key on offering table.
Added migration matching this update to the migrations directory. Mm handy!

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
# Does not include the login page. See login.py.
25
25
 
26
26
import cgi
 
27
import urllib
27
28
import os.path
28
29
 
29
30
import conf
30
31
import conf.apps
31
32
from common import util
 
33
import plugins.console
32
34
 
33
35
def write_html_head(req):
34
36
    """Writes the HTML header, given a request object.
36
38
    req: An IVLE request object. Reads attributes such as title. Also used to
37
39
    write to."""
38
40
 
 
41
    # Let the console plugin insert its own styles and scripts if an app
 
42
    # requests it
 
43
    if req.app is not None and (req.app in conf.apps.app_url and
 
44
                                conf.apps.app_url[req.app].useconsole):
 
45
        plugins.console.insert_scripts_styles(req.scripts, req.styles, \
 
46
            req.scripts_init)
 
47
 
39
48
    # Write the XHTML opening and head element
40
49
    # Note the inline JavaScript, which provides the client with constants
41
50
    # derived from the server configuration.
58
67
        username = "null"
59
68
    req.write("""  <script type="text/javascript">
60
69
    root_dir = %s;
 
70
    public_host = %s;
61
71
    username = %s;
62
72
  </script>
63
 
""" % (repr(conf.root_dir), username))
64
 
    iconurl = get_icon_url(req.app)
 
73
""" % (repr(conf.root_dir), repr(conf.public_host), username))
 
74
    iconurl = get_icon_url(req.app, small=True)
65
75
    if iconurl:
66
76
        req.write("""  <link rel="shortcut icon" href="%s" />
67
77
""" % cgi.escape(iconurl))
75
85
    for script in req.scripts:
76
86
        req.write('  <script type="text/javascript" src="%s"></script>\n'
77
87
            % cgi.escape(util.make_path(script)))
 
88
    req.write('  <script type="text/javascript">\n    /* Init Functions */\n')
 
89
    for init in req.scripts_init:
 
90
        req.write('    window.addEventListener("load", %s, false);\n'%init)
 
91
    req.write('  </script>\n')
78
92
 
79
93
    req.write("</head>\n\n")
80
94
 
89
103
    if req.user:
90
104
        # Get the user's nickname from the request session
91
105
        nickname = req.user.nick
92
 
        req.write('  <p class="userhello">%s (<span '
93
 
            'class="username">%s</span>) |\n'
 
106
        req.write('  <p class="userhello"><span id="usernick">%s</span> '
 
107
            '(<span class="username">%s</span>) |\n'
 
108
            '    <a href="%s">Settings</a> |\n'
94
109
            '    <a href="%s">Help</a> |\n'
95
 
            '    <a href="%s">Logout</a>\n'
 
110
            '    <a href="%s">Sign out</a>\n'
96
111
            '  </p>\n' %
97
112
            (cgi.escape(nickname), cgi.escape(req.user.login),
 
113
             cgi.escape(util.make_path('settings')),
98
114
             cgi.escape(get_help_url(req)),
99
115
             cgi.escape(util.make_path('logout'))))
100
116
    else:
106
122
    # If the "debuginfo" app is installed, display a warning to the admin to
107
123
    # make sure it is removed in production.
108
124
    if "debuginfo" in conf.apps.app_url:
109
 
        req.write("  <p><small>Warning: debuginfo is enabled. Remove this "
110
 
            "app from conf.apps.app_url when placed into production."
111
 
            "</small></p>\n")
 
125
        req.write("  <p><small>Warning: debuginfo is enabled. Set "
 
126
            "enable_debuginfo = False in lib/conf/apps.py, when placing IVLE "
 
127
            "into production.</small></p>\n")
112
128
 
113
129
    # If req has a "no_agreement" attribute, then it is because the user has
114
130
    # not signed the agreement; therefore we are displaying the TOS page.
123
139
 
124
140
    req: An IVLE request object. Written to.
125
141
    """
 
142
    
 
143
    # Write the console html if the app requests it
 
144
    if req.app is not None and (req.app in conf.apps.app_url and
 
145
                                conf.apps.app_url[req.app].useconsole):
 
146
        plugins.console.present(req, windowpane=True)
 
147
 
126
148
    req.write("</div>\n</body>\n</html>\n")
127
149
 
128
150
def get_help_url(req):
143
165
    """Given an app's url name, gets the URL of the icon image for this app,
144
166
    relative to the site root. Returns None if the app has no icon."""
145
167
    if appurl is None: return None
146
 
    app = conf.apps.app_url[appurl]
 
168
    try:
 
169
        app = conf.apps.app_url[appurl]
 
170
    except KeyError:
 
171
        # Due to navigating to a bad app
 
172
        return None
147
173
    if small:
148
174
        icon_dir = conf.apps.app_icon_dir_small
149
175
    else:
169
195
        file.write('    <li%s>' % li_attr)
170
196
        if app.icon:
171
197
            file.write('<img src="%s" alt="" /> '
172
 
                % cgi.escape(get_icon_url(urlname)))
173
 
        file.write('<a href="%s">%s</a></li>\n'
174
 
            % (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
 
198
                % urllib.quote(get_icon_url(urlname)))
 
199
        file.write('<a href="%s" title="%s">%s</a></li>\n'
 
200
            % (urllib.quote(util.make_path(urlname)), cgi.escape(app.desc),
 
201
                cgi.escape(app.name)))
175
202
 
176
203
    file.write('  </ul>\n')