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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-03-07 14:50:44 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:668
user.py: Added last_login as one of the fields which may be passed to the User
        constructor.

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
52
53
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
53
54
    # Write inline JavaScript which gives the client code access to certain
54
55
    # server-side variables.
55
 
    if req.username:
56
 
        username = repr(req.username)
 
56
    if req.user:
 
57
        username = repr(req.user.login)
57
58
    else:
58
59
        username = "null"
59
60
    req.write("""  <script type="text/javascript">
61
62
    username = %s;
62
63
  </script>
63
64
""" % (repr(conf.root_dir), username))
64
 
    iconurl = get_icon_url(req.app)
 
65
    iconurl = get_icon_url(req.app, small=True)
65
66
    if iconurl:
66
67
        req.write("""  <link rel="shortcut icon" href="%s" />
67
68
""" % cgi.escape(iconurl))
86
87
  <h2>Informatics Virtual Learning Environment</h2>
87
88
""")
88
89
 
89
 
    if req.username:
 
90
    if req.user:
90
91
        # 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'
 
92
        nickname = req.user.nick
 
93
        req.write('  <p class="userhello"><span id="usernick">%s</span> '
 
94
            '(<span class="username">%s</span>) |\n'
 
95
            '    <a href="%s">Settings</a> |\n'
94
96
            '    <a href="%s">Help</a> |\n'
95
 
            '    <a href="%s">Logout</a>\n'
 
97
            '    <a href="%s">Sign out</a>\n'
96
98
            '  </p>\n' %
97
 
            (cgi.escape(nickname), cgi.escape(req.username),
 
99
            (cgi.escape(nickname), cgi.escape(req.user.login),
 
100
             cgi.escape(util.make_path('settings')),
98
101
             cgi.escape(get_help_url(req)),
99
102
             cgi.escape(util.make_path('logout'))))
100
103
    else:
106
109
    # If the "debuginfo" app is installed, display a warning to the admin to
107
110
    # make sure it is removed in production.
108
111
    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")
 
112
        req.write("  <p><small>Warning: debuginfo is enabled. Set "
 
113
            "enable_debuginfo = False in lib/conf/apps.py, when placing IVLE "
 
114
            "into production.</small></p>\n")
112
115
 
113
 
    if req.username:
 
116
    # If req has a "no_agreement" attribute, then it is because the user has
 
117
    # not signed the agreement; therefore we are displaying the TOS page.
 
118
    # Do not show apps (see dispatch.login).
 
119
    if req.user and not req.user.state == 'no_agreement':
114
120
        # Only print app tabs if logged in
115
121
        print_apps_list(req, req.app)
116
122
    req.write('</div>\n<div id="ivlebody">\n')
125
131
def get_help_url(req):
126
132
    """Gets the help URL most relevant to this page, to place as the
127
133
    "help" link at the top of the page."""
128
 
    if req.app == 'help':
 
134
    reqapp = req.app if hasattr(req, 'app') else None
 
135
    if reqapp == 'help':
129
136
        # We're already in help. Link to the exact current page
130
137
        # instead of the generic help page.
131
138
        return req.uri
132
 
    if conf.apps.app_url[req.app].hashelp:
133
 
        help_path = os.path.join('help', req.app)
 
139
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
 
140
        help_path = os.path.join('help', reqapp)
134
141
    else:
135
142
        help_path = 'help'
136
143
    return util.make_path(help_path)
139
146
    """Given an app's url name, gets the URL of the icon image for this app,
140
147
    relative to the site root. Returns None if the app has no icon."""
141
148
    if appurl is None: return None
142
 
    app = conf.apps.app_url[appurl]
 
149
    try:
 
150
        app = conf.apps.app_url[appurl]
 
151
    except KeyError:
 
152
        # Due to navigating to a bad app
 
153
        return None
143
154
    if small:
144
155
        icon_dir = conf.apps.app_icon_dir_small
145
156
    else:
165
176
        file.write('    <li%s>' % li_attr)
166
177
        if app.icon:
167
178
            file.write('<img src="%s" alt="" /> '
168
 
                % cgi.escape(get_icon_url(urlname)))
169
 
        file.write('<a href="%s">%s</a></li>\n'
170
 
            % (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
 
179
                % urllib.quote(get_icon_url(urlname)))
 
180
        file.write('<a href="%s" title="%s">%s</a></li>\n'
 
181
            % (urllib.quote(util.make_path(urlname)), cgi.escape(app.desc),
 
182
                cgi.escape(app.name)))
171
183
 
172
184
    file.write('  </ul>\n')