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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-02-03 11:41:36 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:388
browser/listing: Upload button now toggles the upload panel instead of just
displaying it (so clicking it with the panel open now closes the panel).

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