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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: drtomc
  • Date: 2008-02-04 00:21:29 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:396
Alter the apache config so that session objects get stored on disk. We're arranging for the disk in question to be a shared NFS filesystem so users get logged in across all the machines in the cluster. Theoretically.

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:
110
106
    # If the "debuginfo" app is installed, display a warning to the admin to
111
107
    # make sure it is removed in production.
112
108
    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")
 
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")
116
112
 
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':
 
113
    if req.username:
121
114
        # Only print app tabs if logged in
122
115
        print_apps_list(req, req.app)
123
116
    req.write('</div>\n<div id="ivlebody">\n')
132
125
def get_help_url(req):
133
126
    """Gets the help URL most relevant to this page, to place as the
134
127
    "help" link at the top of the page."""
135
 
    reqapp = req.app if hasattr(req, 'app') else None
136
 
    if reqapp == 'help':
 
128
    if req.app == 'help':
137
129
        # We're already in help. Link to the exact current page
138
130
        # instead of the generic help page.
139
131
        return req.uri
140
 
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
141
 
        help_path = os.path.join('help', reqapp)
 
132
    if conf.apps.app_url[req.app].hashelp:
 
133
        help_path = os.path.join('help', req.app)
142
134
    else:
143
135
        help_path = 'help'
144
136
    return util.make_path(help_path)
147
139
    """Given an app's url name, gets the URL of the icon image for this app,
148
140
    relative to the site root. Returns None if the app has no icon."""
149
141
    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
 
142
    app = conf.apps.app_url[appurl]
155
143
    if small:
156
144
        icon_dir = conf.apps.app_icon_dir_small
157
145
    else:
177
165
        file.write('    <li%s>' % li_attr)
178
166
        if app.icon:
179
167
            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)))
 
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)))
184
171
 
185
172
    file.write('  </ul>\n')