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

« back to all changes in this revision

Viewing changes to ivle/dispatch/request.py

  • Committer: William Grant
  • Date: 2009-01-19 23:44:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: grantw@unimelb.edu.au-20090119234435-9f6k53hvpxlr3rcu
bin/ivle-enrol: Port to Storm, reorder the semester and year arguments, give
    nice error messages on all known modes of failure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
object.
26
26
"""
27
27
 
28
 
try:
29
 
    import mod_python.Session
30
 
    import mod_python.Cookie
31
 
    import mod_python.util
32
 
except ImportError:
33
 
    # This needs to be importable from outside Apache.
34
 
    pass
 
28
import mod_python
 
29
from mod_python import (util, Session, Cookie)
35
30
 
36
31
import ivle.util
37
32
import ivle.conf
38
33
import ivle.database
39
 
from ivle.webapp.base.plugins import CookiePlugin
 
34
import plugins.console # XXX: Relies on www/ being in the Python path.
40
35
 
41
36
class Request:
42
37
    """An IVLE request object. This is presented to the IVLE apps as a way of
236
231
        except KeyError:
237
232
            app = None
238
233
 
 
234
        # Write any final modifications to header content
 
235
        if app and app.useconsole and self.user:
 
236
            plugins.console.insert_scripts_styles(self.scripts, self.styles, \
 
237
                self.scripts_init)
 
238
 
239
239
        # Prepare the HTTP and HTML headers before the first write is made
240
240
        if self.content_type != None:
241
241
            self.apache_req.content_type = self.content_type
270
270
    def logout(self):
271
271
        """Log out the current user by destroying the session state.
272
272
        Then redirect to the top-level IVLE page."""
 
273
        # List of cookies that IVLE uses (to be removed at logout)
 
274
        ivle_cookies = ["ivleforumcookie", "clipboard"]
 
275
        
273
276
        if hasattr(self, 'session'):
274
277
            self.session.invalidate()
275
278
            self.session.delete()
276
279
            # Invalidates all IVLE cookies
277
 
            all_cookies = mod_python.Cookie.get_cookies(self)
278
 
 
279
 
            # Create cookies for plugins that might request them.
280
 
            for plugin in self.plugin_index[CookiePlugin]:
281
 
                for cookie in plugin.cookies:
282
 
                    self.add_cookie(mod_python.Cookie.Cookie(cookie, '',
283
 
                                                    expires=1, path='/'))
 
280
            all_cookies = Cookie.get_cookies(self)
 
281
            for cookie in all_cookies:
 
282
                if cookie in ivle_cookies:
 
283
                    self.add_cookie(Cookie.Cookie(cookie,'',expires=1,path='/'))
284
284
        self.throw_redirect(ivle.util.make_path('')) 
285
285
 
286
286
 
327
327
    def add_cookie(self, cookie, value=None, **attributes):
328
328
        """Inserts a cookie into this request object's headers."""
329
329
        if value is None:
330
 
            mod_python.Cookie.add_cookie(self.apache_req, cookie)
 
330
            Cookie.add_cookie(self.apache_req, cookie)
331
331
        else:
332
 
            mod_python.Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
 
332
            Cookie.add_cookie(self.apache_req, cookie, value, **attributes)
333
333
 
334
334
    def get_session(self):
335
335
        """Returns a mod_python Session object for this request.
337
337
        interface if porting away from mod_python."""
338
338
        # Cache the session object and set the timeout to 24 hours.
339
339
        if not hasattr(self, 'session'):
340
 
            self.session = mod_python.Session.FileSession(self.apache_req,
 
340
            self.session = Session.FileSession(self.apache_req,
341
341
                                               timeout = 60 * 60 * 24)
342
342
        return self.session
343
343
 
347
347
        interface if porting away from mod_python."""
348
348
        # Cache the fieldstorage object
349
349
        if not hasattr(self, 'fields'):
350
 
            self.fields = mod_python.util.FieldStorage(self.apache_req)
 
350
            self.fields = util.FieldStorage(self.apache_req)
351
351
        return self.fields
352
352
 
353
353
    def get_cgi_environ(self):