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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: dcoles
  • Date: 2008-08-06 01:32:58 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:981
Groups: Added in support for creating groups in the database through 
userservice (with required capibilities and a new return_insert() database 
function). Implemented create_project_set which requires CAP_MANAGEPROJECTS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# content (the common parts of the HTML pages shared across the entire site).
24
24
# Does not include the login page. See login.py.
25
25
 
 
26
import cgi
 
27
import urllib
26
28
import os.path
27
29
 
28
30
import conf
29
31
import conf.apps
30
32
from common import util
 
33
import plugins.console
31
34
 
32
35
def write_html_head(req):
33
36
    """Writes the HTML header, given a request object.
48
51
<head>
49
52
  <title>%sIVLE</title>
50
53
  <meta http-equiv="Content-Type" content="%s; charset=utf-8" />
51
 
""" % (titlepart, req.content_type))
 
54
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
52
55
    # Write inline JavaScript which gives the client code access to certain
53
56
    # server-side variables.
54
 
    if req.username:
55
 
        username = repr(req.username)
 
57
    if req.user:
 
58
        username = repr(req.user.login)
56
59
    else:
57
60
        username = "null"
58
61
    req.write("""  <script type="text/javascript">
59
62
    root_dir = %s;
 
63
    public_host = %s;
60
64
    username = %s;
61
65
  </script>
62
 
""" % (repr(conf.root_dir), username))
63
 
    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)
64
68
    if iconurl:
65
69
        req.write("""  <link rel="shortcut icon" href="%s" />
66
 
""" % iconurl)
 
70
""" % cgi.escape(iconurl))
67
71
    req.write("""  <link rel="stylesheet" type="text/css" href="%s" />
68
 
""" % util.make_path('media/common/ivle.css'))
 
72
""" % cgi.escape(util.make_path('media/common/ivle.css')))
69
73
 
70
74
    # Write any app-specific style and script links
71
75
    for style in req.styles:
72
76
        req.write('  <link rel="stylesheet" type="text/css" href="%s" />\n'
73
 
            % util.make_path(style))
 
77
            % cgi.escape(util.make_path(style)))
74
78
    for script in req.scripts:
75
 
        req.write('  <script type="text/javascript" src="%s" />\n'
76
 
            % util.make_path(script))
 
79
        req.write('  <script type="text/javascript" src="%s"></script>\n'
 
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')
77
85
 
78
86
    req.write("</head>\n\n")
79
87
 
80
88
    # Open the body element and write a bunch of stuff there (the header)
81
89
    req.write("""<body>
82
 
<div id="ivleheader">
 
90
<div id="ivleheader"></div>
 
91
<div id="ivleheader_text">
83
92
  <h1>IVLE</h1>
84
93
  <h2>Informatics Virtual Learning Environment</h2>
85
94
""")
86
95
 
87
 
    if req.username:
88
 
        req.write('  <p class="userhello">Welcome, <span '
89
 
            'class="username">%s</span> |\n'
 
96
    if req.publicmode:
 
97
        req.write('   <p class="userhello">Running in public mode.</p>')
 
98
    elif req.user:
 
99
        # Get the user's nickname from the request session
 
100
        nickname = req.user.nick
 
101
        req.write('  <p class="userhello"><span id="usernick">%s</span> '
 
102
            '(<span class="username">%s</span>) |\n'
 
103
            '    <a href="%s">Settings</a> |\n'
90
104
            '    <a href="%s">Help</a> |\n'
91
 
            '    <a href="%s">Logout</a>\n'
 
105
            '    <a href="%s">Sign out</a>\n'
92
106
            '  </p>\n' %
93
 
            (req.username, get_help_url(req), util.make_path('logout')))
 
107
            (cgi.escape(nickname), cgi.escape(req.user.login),
 
108
             cgi.escape(util.make_path('settings')),
 
109
             cgi.escape(get_help_url(req)),
 
110
             cgi.escape(util.make_path('logout'))))
94
111
    else:
95
112
        req.write('  <p class="userhello">Not logged in.</p>')
96
113
 
 
114
    # ivleheader_tabs is a separate div, so it can be positioned absolutely
 
115
    req.write('</div>\n<div id="ivleheader_tabs">\n')
 
116
 
97
117
    # If the "debuginfo" app is installed, display a warning to the admin to
98
118
    # make sure it is removed in production.
99
119
    if "debuginfo" in conf.apps.app_url:
100
 
        req.write("  <p><small>Warning: debuginfo is enabled. Remove this "
101
 
            "app from conf.apps.app_url when placed into production."
102
 
            "</small></p>\n")
 
120
        req.write("  <p><small>Warning: debuginfo is enabled. Set "
 
121
            "enable_debuginfo = False in lib/conf/apps.py, when placing IVLE "
 
122
            "into production.</small></p>\n")
103
123
 
104
 
    if req.username:
 
124
    # If req has a "no_agreement" attribute, then it is because the user has
 
125
    # not signed the agreement; therefore we are displaying the TOS page.
 
126
    # Do not show apps (see dispatch.login).
 
127
    if req.user and not req.user.state == 'no_agreement':
105
128
        # Only print app tabs if logged in
106
129
        print_apps_list(req, req.app)
107
130
    req.write('</div>\n<div id="ivlebody">\n')
116
139
def get_help_url(req):
117
140
    """Gets the help URL most relevant to this page, to place as the
118
141
    "help" link at the top of the page."""
119
 
    if req.app == 'help':
 
142
    reqapp = req.app if hasattr(req, 'app') else None
 
143
    if reqapp == 'help':
120
144
        # We're already in help. Link to the exact current page
121
145
        # instead of the generic help page.
122
146
        return req.uri
123
 
    if conf.apps.app_url[req.app].hashelp:
124
 
        help_path = os.path.join('help', req.app)
 
147
    if reqapp is not None and reqapp in conf.apps.app_url and \
 
148
        conf.apps.app_url[reqapp].hashelp:
 
149
        help_path = os.path.join('help', reqapp)
125
150
    else:
126
151
        help_path = 'help'
127
152
    return util.make_path(help_path)
130
155
    """Given an app's url name, gets the URL of the icon image for this app,
131
156
    relative to the site root. Returns None if the app has no icon."""
132
157
    if appurl is None: return None
133
 
    app = conf.apps.app_url[appurl]
 
158
    try:
 
159
        app = conf.apps.app_url[appurl]
 
160
    except KeyError:
 
161
        # Due to navigating to a bad app
 
162
        return None
134
163
    if small:
135
164
        icon_dir = conf.apps.app_icon_dir_small
136
165
    else:
145
174
    file: Object with a "write" method - ie. the request object.
146
175
    Reads from: conf
147
176
    """
148
 
    file.write('  <ul class="apptabs">\n')
 
177
    file.write('  <ul id="apptabs">\n')
149
178
 
150
179
    for urlname in conf.apps.apps_in_tabs:
151
180
        app = conf.apps.app_url[urlname]
155
184
            li_attr = ''
156
185
        file.write('    <li%s>' % li_attr)
157
186
        if app.icon:
158
 
            file.write('<img src="%s" alt="" /> ' % get_icon_url(urlname))
159
 
        file.write('<a href="%s">%s</a></li>\n'
160
 
            % (util.make_path(urlname), app.name))
 
187
            file.write('<img src="%s" alt="" /> '
 
188
                % urllib.quote(get_icon_url(urlname)))
 
189
        file.write('<a href="%s" title="%s">%s</a></li>\n'
 
190
            % (urllib.quote(util.make_path(urlname)), cgi.escape(app.desc),
 
191
                cgi.escape(app.name)))
161
192
 
162
193
    file.write('  </ul>\n')