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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: wagrant
  • Date: 2008-09-20 07:56:43 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1055
www.dispatch: Don't sent incomplete XHTML for either type of error.

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.
52
54
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
53
55
    # Write inline JavaScript which gives the client code access to certain
54
56
    # server-side variables.
55
 
    if req.username:
56
 
        username = repr(req.username)
 
57
    if req.user:
 
58
        username = repr(req.user.login)
57
59
    else:
58
60
        username = "null"
59
61
    req.write("""  <script type="text/javascript">
60
62
    root_dir = %s;
 
63
    public_host = %s;
61
64
    username = %s;
62
65
  </script>
63
 
""" % (repr(conf.root_dir), username))
64
 
    iconurl = get_icon_url(req.app)
 
66
""" % (repr(conf.root_dir), repr(conf.public_host), username))
 
67
    iconurl = get_icon_url(req.app, small=True)
65
68
    if iconurl:
66
69
        req.write("""  <link rel="shortcut icon" href="%s" />
67
70
""" % cgi.escape(iconurl))
75
78
    for script in req.scripts:
76
79
        req.write('  <script type="text/javascript" src="%s"></script>\n'
77
80
            % cgi.escape(util.make_path(script)))
 
81
    if len(req.scripts_init) > 0:
 
82
        req.write('  <script type="text/javascript">\n    /* Init Functions */\n')
 
83
        for init in req.scripts_init:
 
84
            req.write('    window.addEventListener("load", %s, false);\n'%init)
 
85
        req.write('  </script>\n')
78
86
 
79
87
    req.write("</head>\n\n")
80
88
 
86
94
  <h2>Informatics Virtual Learning Environment</h2>
87
95
""")
88
96
 
89
 
    if req.username:
 
97
    if req.publicmode:
 
98
        req.write('   <p class="userhello">Running in public mode.</p>')
 
99
    elif req.user:
90
100
        # Get the user's nickname from the request session
91
 
        nickname = req.get_session()['nick']
92
 
        req.write('  <p class="userhello">%s (<span '
93
 
            'class="username">%s</span>) |\n'
 
101
        nickname = req.user.nick
 
102
        req.write('  <p class="userhello"><span id="usernick">%s</span> '
 
103
            '(<span class="username">%s</span>) |\n'
 
104
            '    <a href="%s">Settings</a> |\n'
94
105
            '    <a href="%s">Help</a> |\n'
95
 
            '    <a href="%s">Logout</a>\n'
 
106
            '    <a href="%s">Sign out</a>\n'
96
107
            '  </p>\n' %
97
 
            (cgi.escape(nickname), cgi.escape(req.username),
 
108
            (cgi.escape(nickname), cgi.escape(req.user.login),
 
109
             cgi.escape(util.make_path('settings')),
98
110
             cgi.escape(get_help_url(req)),
99
111
             cgi.escape(util.make_path('logout'))))
100
112
    else:
106
118
    # If the "debuginfo" app is installed, display a warning to the admin to
107
119
    # make sure it is removed in production.
108
120
    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")
 
121
        req.write("  <p><small>Warning: debuginfo is enabled. Set "
 
122
            "enable_debuginfo = False in lib/conf/apps.py, when placing IVLE "
 
123
            "into production.</small></p>\n")
112
124
 
113
125
    # If req has a "no_agreement" attribute, then it is because the user has
114
126
    # not signed the agreement; therefore we are displaying the TOS page.
115
127
    # Do not show apps (see dispatch.login).
116
 
    if req.username and not hasattr(req, 'no_agreement'):
 
128
    if req.user and not req.user.state == 'no_agreement':
117
129
        # Only print app tabs if logged in
118
130
        print_apps_list(req, req.app)
119
131
    req.write('</div>\n<div id="ivlebody">\n')
133
145
        # We're already in help. Link to the exact current page
134
146
        # instead of the generic help page.
135
147
        return req.uri
136
 
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
 
148
    if reqapp is not None and reqapp in conf.apps.app_url and \
 
149
        conf.apps.app_url[reqapp].hashelp:
137
150
        help_path = os.path.join('help', reqapp)
138
151
    else:
139
152
        help_path = 'help'
143
156
    """Given an app's url name, gets the URL of the icon image for this app,
144
157
    relative to the site root. Returns None if the app has no icon."""
145
158
    if appurl is None: return None
146
 
    app = conf.apps.app_url[appurl]
 
159
    try:
 
160
        app = conf.apps.app_url[appurl]
 
161
    except KeyError:
 
162
        # Due to navigating to a bad app
 
163
        return None
147
164
    if small:
148
165
        icon_dir = conf.apps.app_icon_dir_small
149
166
    else:
169
186
        file.write('    <li%s>' % li_attr)
170
187
        if app.icon:
171
188
            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)))
 
189
                % urllib.quote(get_icon_url(urlname)))
 
190
        file.write('<a href="%s" title="%s">%s</a></li>\n'
 
191
            % (urllib.quote(util.make_path(urlname)), cgi.escape(app.desc),
 
192
                cgi.escape(app.name)))
175
193
 
176
194
    file.write('  </ul>\n')