37
42
# Note the inline JavaScript, which provides the client with constants
38
43
# derived from the server configuration.
39
44
if req.title != None:
40
titlepart = ' - ' + req.title
45
titlepart = req.title + ' - '
43
48
req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
44
49
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
45
50
<html xmlns="http://www.w3.org/1999/xhtml">
48
53
<meta http-equiv="Content-Type" content="%s; charset=utf-8" />
49
<script type="text/javascript">
54
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
55
# Write inline JavaScript which gives the client code access to certain
56
# server-side variables.
58
username = repr(req.user.login)
61
if req.write_javascript_settings:
62
req.write(""" <script type="text/javascript">
52
<link rel="stylesheet" type="text/css" href="%s" />
53
""" % (titlepart, req.content_type,
54
repr(conf.root_dir)[1:-1],
55
util.make_path('media/common/ivle.css')))
67
""" % (repr(conf.root_dir), repr(conf.public_host), username))
68
iconurl = get_icon_url(req.app, small=True)
70
req.write(""" <link rel="shortcut icon" href="%s" />
71
""" % cgi.escape(iconurl))
72
req.write(""" <link rel="stylesheet" type="text/css" href="%s" />
73
""" % cgi.escape(util.make_path('media/common/ivle.css')))
57
75
# Write any app-specific style and script links
58
76
for style in req.styles:
59
77
req.write(' <link rel="stylesheet" type="text/css" href="%s" />\n'
60
% util.make_path(style))
78
% cgi.escape(util.make_path(style)))
61
79
for script in req.scripts:
62
req.write(' <script type="text/javascript" src="%s" />\n'
63
% util.make_path(script))
80
req.write(' <script type="text/javascript" src="%s"></script>\n'
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')
65
88
req.write("</head>\n\n")
67
90
# Open the body element and write a bunch of stuff there (the header)
68
91
req.write("""<body>
69
<h1>IVLE - Informatics Virtual Learning Environment</h1>
92
<div id="ivleheader"></div>
93
<div id="ivleheader_text">
95
<h2>Informatics Virtual Learning Environment</h2>
73
req.write("""<p>Hello, %s. <a href="%s">Logout</a></p>\n""" %
74
(req.username, util.make_path('logout')))
99
req.write(' <p class="userhello">Running in public mode.</p>')
101
# Get the user's nickname from the request session
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'
106
' <a href="%s">Help</a> |\n'
107
' <a href="%s">Sign out</a>\n'
109
(cgi.escape(nickname), cgi.escape(req.user.login),
110
cgi.escape(util.make_path('settings')),
111
cgi.escape(get_help_url(req)),
112
cgi.escape(util.make_path('logout'))))
76
req.write("<p>Not logged in.</p>")
114
req.write(' <p class="userhello">Not logged in.</p>')
116
# ivleheader_tabs is a separate div, so it can be positioned absolutely
117
req.write('</div>\n<div id="ivleheader_tabs">\n')
78
119
# If the "debuginfo" app is installed, display a warning to the admin to
79
120
# make sure it is removed in production.
80
121
if "debuginfo" in conf.apps.app_url:
81
req.write("<p>Warning: debuginfo is enabled. Remove this app from "
82
"conf.apps.app_url when placed into production.</p>\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")
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':
130
# Only print app tabs if logged in
131
print_apps_list(req, req.app)
132
req.write('</div>\n<div id="ivlebody">\n')
86
134
def write_html_foot(req):
87
135
"""Writes the HTML footer, given a request object.
89
137
req: An IVLE request object. Written to.
91
req.write("</body>\n</html>\n")
93
def print_apps_list(file):
139
req.write("</div>\n</body>\n</html>\n")
141
def get_help_url(req):
142
"""Gets the help URL most relevant to this page, to place as the
143
"help" link at the top of the page."""
144
reqapp = req.app if hasattr(req, 'app') else None
146
# We're already in help. Link to the exact current page
147
# instead of the generic help page.
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)
154
return util.make_path(help_path)
156
def get_icon_url(appurl, small=False):
157
"""Given an app's url name, gets the URL of the icon image for this app,
158
relative to the site root. Returns None if the app has no icon."""
159
if appurl is None: return None
161
app = conf.apps.app_url[appurl]
163
# Due to navigating to a bad app
166
icon_dir = conf.apps.app_icon_dir_small
168
icon_dir = conf.apps.app_icon_dir
169
if app.icon is None: return None
170
return util.make_path(os.path.join(icon_dir, app.icon))
172
def print_apps_list(file, thisapp):
94
173
"""Prints all app tabs, as a UL. Prints a list item for each app that has
97
176
file: Object with a "write" method - ie. the request object.
100
file.write('<ul class="apptabs">\n')
179
file.write(' <ul id="apptabs">\n')
102
181
for urlname in conf.apps.apps_in_tabs:
103
182
app = conf.apps.app_url[urlname]
104
file.write(' <li><a href="%s">%s</a></li>\n'
105
% (util.make_path(urlname), app.name))
183
if urlname == thisapp:
184
li_attr = ' class="thisapp"'
187
file.write(' <li%s>' % li_attr)
189
file.write('<img src="%s" alt="" /> '
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)))
107
file.write('</ul>\n')
195
file.write(' </ul>\n')