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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: wagrant
  • Date: 2008-07-16 04:35:05 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:889
common.svn: Add a method to check if a path has the specified revision.
fileservice_lib: Die if an invalid revision was specified.

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