54
52
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
55
53
# Write inline JavaScript which gives the client code access to certain
56
54
# server-side variables.
58
username = repr(req.user.login)
56
username = repr(req.username)
61
if req.write_javascript_settings:
62
req.write(""" <script type="text/javascript">
59
req.write(""" <script type="text/javascript">
67
""" % (repr(conf.root_dir), repr(conf.public_host), username))
68
iconurl = get_icon_url(req.app, small=True)
63
""" % (repr(conf.root_dir), username))
64
iconurl = get_icon_url(req.app)
70
66
req.write(""" <link rel="shortcut icon" href="%s" />
71
67
""" % cgi.escape(iconurl))
77
73
req.write(' <link rel="stylesheet" type="text/css" href="%s" />\n'
78
74
% cgi.escape(util.make_path(style)))
79
75
for script in req.scripts:
80
req.write(' <script type="text/javascript" src="%s"></script>\n'
76
req.write(' <script type="text/javascript" src="%s" />\n'
81
77
% 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')
88
79
req.write("</head>\n\n")
90
81
# Open the body element and write a bunch of stuff there (the header)
91
82
req.write("""<body>
92
<div id="ivleheader"></div>
93
<div id="ivleheader_text">
95
85
<h2>Informatics Virtual Learning Environment</h2>
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'
89
req.write(' <p class="userhello">Welcome, <span '
90
'class="username">%s</span> |\n'
106
91
' <a href="%s">Help</a> |\n'
107
' <a href="%s">Sign out</a>\n'
92
' <a href="%s">Logout</a>\n'
109
(cgi.escape(nickname), cgi.escape(req.user.login),
110
cgi.escape(util.make_path('settings')),
94
(cgi.escape(req.username),
111
95
cgi.escape(get_help_url(req)),
112
96
cgi.escape(util.make_path('logout'))))
114
98
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')
119
100
# If the "debuginfo" app is installed, display a warning to the admin to
120
101
# make sure it is removed in production.
121
102
if "debuginfo" in conf.apps.app_url:
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")
103
req.write(" <p><small>Warning: debuginfo is enabled. Remove this "
104
"app from conf.apps.app_url when placed into production."
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
108
# Only print app tabs if logged in
131
109
print_apps_list(req, req.app)
132
110
req.write('</div>\n<div id="ivlebody">\n')
141
119
def get_help_url(req):
142
120
"""Gets the help URL most relevant to this page, to place as the
143
121
"help" link at the top of the page."""
144
reqapp = req.app if hasattr(req, 'app') else None
122
if req.app == 'help':
146
123
# We're already in help. Link to the exact current page
147
124
# 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)
126
if conf.apps.app_url[req.app].hashelp:
127
help_path = os.path.join('help', req.app)
153
129
help_path = 'help'
154
130
return util.make_path(help_path)
157
133
"""Given an app's url name, gets the URL of the icon image for this app,
158
134
relative to the site root. Returns None if the app has no icon."""
159
135
if appurl is None: return None
161
app = conf.apps.app_url[appurl]
163
# Due to navigating to a bad app
136
app = conf.apps.app_url[appurl]
166
138
icon_dir = conf.apps.app_icon_dir_small
187
159
file.write(' <li%s>' % li_attr)
189
161
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)))
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)))
195
166
file.write(' </ul>\n')