80
79
String. Response "Location" header value. Used with HTTP redirect
82
List of strings. Write a list of URLs to CSS files here, and they
83
will be incorporated as <link rel="stylesheet" type="text/css">
84
elements in the head, if write_html_head_foot is True.
85
URLs should be relative to the IVLE root; they will be fixed up
88
List of strings. Write a list of URLs to JS files here, and they
89
will be incorporated as <script type="text/javascript"> elements
90
in the head, if write_html_head_foot is True.
91
URLs should be relative to the IVLE root; they will be fixed up
94
List of strings. Write a list of JS function names, and they
95
will be added as window.addListener('load', ..., false); calls
96
in the head, if write_html_head_foot is True.
97
This is the propper way to specify functions that need to run at
84
101
# Special code for an OK response.
137
154
HTTP_INSUFFICIENT_STORAGE = 507
138
155
HTTP_NOT_EXTENDED = 510
140
def __init__(self, req, config):
141
"""Create an IVLE request from a mod_python one.
157
def __init__(self, req):
158
"""Builds an IVLE request object from a mod_python request object.
159
This results in an object with all of the necessary methods and
143
@param req: A mod_python request.
144
@param config: An IVLE configuration.
162
req: A mod_python request object.
147
165
# Methods are mostly wrappers around the Apache request object
148
166
self.apache_req = req
150
167
self.headers_written = False
152
169
# Determine if the browser used the public host name to make the
153
170
# request (in which case we are in "public mode")
154
if req.hostname == config['urls']['public_host']:
171
if req.hostname == ivle.conf.public_host:
155
172
self.publicmode = True
157
174
self.publicmode = False
161
178
self.uri = req.uri
162
179
# Split the given path into the app (top-level dir) and sub-path
163
180
# (after first stripping away the root directory)
164
path = self.unmake_path(req.uri)
181
path = ivle.util.unmake_path(req.uri)
165
182
(self.app, self.path) = (ivle.util.split_path(path))
167
184
self.hostname = req.hostname
171
188
# Open a database connection and transaction, keep it around for users
172
189
# of the Request object to use
173
self.store = ivle.database.get_store(config)
190
self.store = ivle.database.get_store()
175
192
# Default values for the output members
176
193
self.status = Request.HTTP_OK
177
194
self.content_type = None # Use Apache's default
178
195
self.location = None
198
self.scripts_init = []
179
199
# In some cases we don't want the template JS (such as the username
180
200
# and public FQDN) in the output HTML. In that case, set this to 0.
181
201
self.write_javascript_settings = True
232
252
for cookie in plugin.cookies:
233
253
self.add_cookie(mod_python.Cookie.Cookie(cookie, '',
234
254
expires=1, path='/'))
235
self.throw_redirect(self.make_path(''))
255
self.throw_redirect(ivle.util.make_path(''))
273
293
mod_python.Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
275
def make_path(self, path):
276
"""Prepend the IVLE URL prefix to the given path.
278
This is used when generating URLs to send to the client.
280
This method is DEPRECATED. We no longer support use of a prefix.
282
return os.path.join(self.config['urls']['root'], path)
284
def unmake_path(self, path):
285
"""Strip the IVLE URL prefix from the given path, if present.
287
Also normalises the path.
289
This method is DEPRECATED. We no longer support use of a prefix.
291
path = os.path.normpath(path)
292
root = os.path.normpath(self.config['urls']['root'])
294
if path.startswith(root):
295
path = path[len(root):]
296
# Take out the slash as well
297
if len(path) > 0 and path[0] == os.sep:
302
295
def get_session(self):
303
296
"""Returns a mod_python Session object for this request.
304
297
Note that this is dependent on mod_python and may need to change
305
interface if porting away from mod_python.
307
IMPORTANT: Call unlock() on the session as soon as you are done with
308
it! If you don't, all other requests will block!
298
interface if porting away from mod_python."""
310
299
# Cache the session object and set the timeout to 24 hours.
311
300
if not hasattr(self, 'session'):
312
301
self.session = mod_python.Session.FileSession(self.apache_req,