~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 23:06:26 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:404
Version 0 of the usrmgt server.
1. doesn't make the jail yet.
2. doesn't sync the passwd files properly (I'm sure Wilson muttered the words "shadow password file" at some point in our conversation).

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
31
30
import conf.apps
32
31
from common import util
33
 
import plugins.console
34
32
 
35
33
def write_html_head(req):
36
34
    """Writes the HTML header, given a request object.
38
36
    req: An IVLE request object. Reads attributes such as title. Also used to
39
37
    write to."""
40
38
 
41
 
    # Let the console plugin insert its own styles and scripts if an app
42
 
    # requests it
43
 
    if req.app is not None and (req.app in conf.apps.app_url and
44
 
                                conf.apps.app_url[req.app].useconsole):
45
 
        plugins.console.insert_scripts_styles(req.scripts, req.styles, \
46
 
            req.scripts_init)
47
 
 
48
39
    # Write the XHTML opening and head element
49
40
    # Note the inline JavaScript, which provides the client with constants
50
41
    # derived from the server configuration.
61
52
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
62
53
    # Write inline JavaScript which gives the client code access to certain
63
54
    # server-side variables.
64
 
    if req.user:
65
 
        username = repr(req.user.login)
 
55
    if req.username:
 
56
        username = repr(req.username)
66
57
    else:
67
58
        username = "null"
68
59
    req.write("""  <script type="text/javascript">
69
60
    root_dir = %s;
70
 
    public_host = %s;
71
61
    username = %s;
72
62
  </script>
73
 
""" % (repr(conf.root_dir), repr(conf.public_host), username))
74
 
    iconurl = get_icon_url(req.app, small=True)
 
63
""" % (repr(conf.root_dir), username))
 
64
    iconurl = get_icon_url(req.app)
75
65
    if iconurl:
76
66
        req.write("""  <link rel="shortcut icon" href="%s" />
77
67
""" % cgi.escape(iconurl))
83
73
        req.write('  <link rel="stylesheet" type="text/css" href="%s" />\n'
84
74
            % cgi.escape(util.make_path(style)))
85
75
    for script in req.scripts:
86
 
        req.write('  <script type="text/javascript" src="%s"></script>\n'
 
76
        req.write('  <script type="text/javascript" src="%s" />\n'
87
77
            % cgi.escape(util.make_path(script)))
88
 
    req.write('  <script type="text/javascript">\n    /* Init Functions */\n')
89
 
    for init in req.scripts_init:
90
 
        req.write('    window.addEventListener("load", %s, false);\n'%init)
91
 
    req.write('  </script>\n')
92
78
 
93
79
    req.write("</head>\n\n")
94
80
 
100
86
  <h2>Informatics Virtual Learning Environment</h2>
101
87
""")
102
88
 
103
 
    if req.user:
 
89
    if req.username:
104
90
        # Get the user's nickname from the request session
105
 
        nickname = req.user.nick
106
 
        req.write('  <p class="userhello"><span id="usernick">%s</span> '
107
 
            '(<span class="username">%s</span>) |\n'
108
 
            '    <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'
109
94
            '    <a href="%s">Help</a> |\n'
110
 
            '    <a href="%s">Sign out</a>\n'
 
95
            '    <a href="%s">Logout</a>\n'
111
96
            '  </p>\n' %
112
 
            (cgi.escape(nickname), cgi.escape(req.user.login),
113
 
             cgi.escape(util.make_path('settings')),
 
97
            (cgi.escape(nickname), cgi.escape(req.username),
114
98
             cgi.escape(get_help_url(req)),
115
99
             cgi.escape(util.make_path('logout'))))
116
100
    else:
122
106
    # If the "debuginfo" app is installed, display a warning to the admin to
123
107
    # make sure it is removed in production.
124
108
    if "debuginfo" in conf.apps.app_url:
125
 
        req.write("  <p><small>Warning: debuginfo is enabled. Set "
126
 
            "enable_debuginfo = False in lib/conf/apps.py, when placing IVLE "
127
 
            "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")
128
112
 
129
 
    # If req has a "no_agreement" attribute, then it is because the user has
130
 
    # not signed the agreement; therefore we are displaying the TOS page.
131
 
    # Do not show apps (see dispatch.login).
132
 
    if req.user and not req.user.state == 'no_agreement':
 
113
    if req.username:
133
114
        # Only print app tabs if logged in
134
115
        print_apps_list(req, req.app)
135
116
    req.write('</div>\n<div id="ivlebody">\n')
139
120
 
140
121
    req: An IVLE request object. Written to.
141
122
    """
142
 
    
143
 
    # Write the console html if the app requests it
144
 
    if req.app is not None and (req.app in conf.apps.app_url and
145
 
                                conf.apps.app_url[req.app].useconsole):
146
 
        plugins.console.present(req, windowpane=True)
147
 
 
148
123
    req.write("</div>\n</body>\n</html>\n")
149
124
 
150
125
def get_help_url(req):
151
126
    """Gets the help URL most relevant to this page, to place as the
152
127
    "help" link at the top of the page."""
153
 
    reqapp = req.app if hasattr(req, 'app') else None
154
 
    if reqapp == 'help':
 
128
    if req.app == 'help':
155
129
        # We're already in help. Link to the exact current page
156
130
        # instead of the generic help page.
157
131
        return req.uri
158
 
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
159
 
        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)
160
134
    else:
161
135
        help_path = 'help'
162
136
    return util.make_path(help_path)
165
139
    """Given an app's url name, gets the URL of the icon image for this app,
166
140
    relative to the site root. Returns None if the app has no icon."""
167
141
    if appurl is None: return None
168
 
    try:
169
 
        app = conf.apps.app_url[appurl]
170
 
    except KeyError:
171
 
        # Due to navigating to a bad app
172
 
        return None
 
142
    app = conf.apps.app_url[appurl]
173
143
    if small:
174
144
        icon_dir = conf.apps.app_icon_dir_small
175
145
    else:
195
165
        file.write('    <li%s>' % li_attr)
196
166
        if app.icon:
197
167
            file.write('<img src="%s" alt="" /> '
198
 
                % urllib.quote(get_icon_url(urlname)))
199
 
        file.write('<a href="%s" title="%s">%s</a></li>\n'
200
 
            % (urllib.quote(util.make_path(urlname)), cgi.escape(app.desc),
201
 
                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)))
202
171
 
203
172
    file.write('  </ul>\n')