~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-01 05:48:34 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:371
setup.py: Fixed chmodding python-console. (Turns out this was a bug in setup,
    not a missing action).

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:
92
 
        # 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'
 
89
    if req.username:
 
90
        req.write('  <p class="userhello">Welcome, <span '
 
91
            'class="username">%s</span> |\n'
97
92
            '    <a href="%s">Help</a> |\n'
98
 
            '    <a href="%s">Sign out</a>\n'
 
93
            '    <a href="%s">Logout</a>\n'
99
94
            '  </p>\n' %
100
 
            (cgi.escape(nickname), cgi.escape(req.user.login),
101
 
             cgi.escape(util.make_path('settings')),
 
95
            (cgi.escape(req.username),
102
96
             cgi.escape(get_help_url(req)),
103
97
             cgi.escape(util.make_path('logout'))))
104
98
    else:
105
99
        req.write('  <p class="userhello">Not logged in.</p>')
106
100
 
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
101
    # If the "debuginfo" app is installed, display a warning to the admin to
111
102
    # make sure it is removed in production.
112
103
    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")
 
104
        req.write("  <p><small>Warning: debuginfo is enabled. Remove this "
 
105
            "app from conf.apps.app_url when placed into production."
 
106
            "</small></p>\n")
 
107
    # ivleheader_tabs is a separate div, so it can be positioned absolutely
 
108
    req.write('</div>\n<div id="ivleheader_tabs">\n')
116
109
 
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':
 
110
    if req.username:
121
111
        # Only print app tabs if logged in
122
112
        print_apps_list(req, req.app)
123
113
    req.write('</div>\n<div id="ivlebody">\n')
132
122
def get_help_url(req):
133
123
    """Gets the help URL most relevant to this page, to place as the
134
124
    "help" link at the top of the page."""
135
 
    reqapp = req.app if hasattr(req, 'app') else None
136
 
    if reqapp == 'help':
 
125
    if req.app == 'help':
137
126
        # We're already in help. Link to the exact current page
138
127
        # instead of the generic help page.
139
128
        return req.uri
140
 
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
141
 
        help_path = os.path.join('help', reqapp)
 
129
    if conf.apps.app_url[req.app].hashelp:
 
130
        help_path = os.path.join('help', req.app)
142
131
    else:
143
132
        help_path = 'help'
144
133
    return util.make_path(help_path)
147
136
    """Given an app's url name, gets the URL of the icon image for this app,
148
137
    relative to the site root. Returns None if the app has no icon."""
149
138
    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
 
139
    app = conf.apps.app_url[appurl]
155
140
    if small:
156
141
        icon_dir = conf.apps.app_icon_dir_small
157
142
    else:
177
162
        file.write('    <li%s>' % li_attr)
178
163
        if app.icon:
179
164
            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)))
 
165
                % cgi.escape(get_icon_url(urlname)))
 
166
        file.write('<a href="%s">%s</a></li>\n'
 
167
            % (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
184
168
 
185
169
    file.write('  </ul>\n')