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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: drtomc
  • Date: 2008-03-04 01:17:10 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:636
remakeuser: use the database, not the password file.

Show diffs side-by-side

added added

removed removed

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