38
36
req: An IVLE request object. Reads attributes such as title. Also used to
41
# Let the console plugin insert its own styles and scripts if an app
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, \
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.
65
username = repr(req.user.login)
56
username = repr(req.username)
68
59
req.write(""" <script type="text/javascript">
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)
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')
93
79
req.write("</head>\n\n")
95
81
# Open the body element and write a bunch of stuff there (the header)
96
82
req.write("""<body>
97
<div id="ivleheader"></div>
98
<div id="ivleheader_text">
100
85
<h2>Informatics Virtual Learning Environment</h2>
104
# 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'
89
req.write(' <p class="userhello">Welcome, <span '
90
'class="username">%s</span> |\n'
109
91
' <a href="%s">Help</a> |\n'
110
' <a href="%s">Sign out</a>\n'
92
' <a href="%s">Logout</a>\n'
112
(cgi.escape(nickname), cgi.escape(req.user.login),
113
cgi.escape(util.make_path('settings')),
94
(cgi.escape(req.username),
114
95
cgi.escape(get_help_url(req)),
115
96
cgi.escape(util.make_path('logout'))))
117
98
req.write(' <p class="userhello">Not logged in.</p>')
119
# ivleheader_tabs is a separate div, so it can be positioned absolutely
120
req.write('</div>\n<div id="ivleheader_tabs">\n')
122
100
# If the "debuginfo" app is installed, display a warning to the admin to
123
101
# make sure it is removed in production.
124
102
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")
103
req.write(" <p><small>Warning: debuginfo is enabled. Remove this "
104
"app from conf.apps.app_url when placed into production."
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':
133
108
# Only print app tabs if logged in
134
109
print_apps_list(req, req.app)
135
110
req.write('</div>\n<div id="ivlebody">\n')
140
115
req: An IVLE request object. Written to.
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)
148
117
req.write("</div>\n</body>\n</html>\n")
150
119
def get_help_url(req):
151
120
"""Gets the help URL most relevant to this page, to place as the
152
121
"help" link at the top of the page."""
153
reqapp = req.app if hasattr(req, 'app') else None
122
if req.app == 'help':
155
123
# We're already in help. Link to the exact current page
156
124
# instead of the generic help page.
158
if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
159
help_path = os.path.join('help', reqapp)
126
if conf.apps.app_url[req.app].hashelp:
127
help_path = os.path.join('help', req.app)
161
129
help_path = 'help'
162
130
return util.make_path(help_path)
165
133
"""Given an app's url name, gets the URL of the icon image for this app,
166
134
relative to the site root. Returns None if the app has no icon."""
167
135
if appurl is None: return None
169
app = conf.apps.app_url[appurl]
171
# Due to navigating to a bad app
136
app = conf.apps.app_url[appurl]
174
138
icon_dir = conf.apps.app_icon_dir_small
195
159
file.write(' <li%s>' % li_attr)
197
161
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)))
162
% cgi.escape(get_icon_url(urlname)))
163
file.write('<a href="%s">%s</a></li>\n'
164
% (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
203
166
file.write(' </ul>\n')