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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: wagrant
  • Date: 2008-09-22 23:33:33 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1058
fileservice_lib.action.action_putfiles: Catch IOErrors when writing
    to normal files, not just when extracting from ZIPs. Lots of
    people were getting them when uploading a file with the same
    name as a directory.

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