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

« back to all changes in this revision

Viewing changes to www/dispatch/__init__.py

  • Committer: stevenbird
  • Date: 2008-02-19 21:17:21 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:512
Renaming of problems to exercises (initial commit).
Fix up module naming (exercises sometimes called tutorials).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
from request import Request
39
39
import html
40
40
import login
41
 
from common import util
 
41
from common import (util, forumutil)
42
42
 
43
43
def handler(req):
44
44
    """Handles a request which may be to anywhere in the site except media.
59
59
            # TODO: Nicer 404 message?
60
60
            req.throw_error(Request.HTTP_NOT_FOUND)
61
61
 
 
62
    # Special handling for public mode - just call public app and get out
 
63
    # NOTE: This will not behave correctly if the public app uses
 
64
    # write_html_head_foot, but "serve" does not.
 
65
    if req.publicmode:
 
66
        app = conf.apps.app_url[conf.apps.public_app]
 
67
        apps.call_app(app.dir, req)
 
68
        return req.OK
 
69
 
62
70
    # app is the App object for the chosen app
63
71
    if req.app is None:
64
 
        app = conf.apps.app_url[conf.default_app]
 
72
        app = conf.apps.app_url[conf.apps.default_app]
65
73
    else:
66
74
        app = conf.apps.app_url[req.app]
67
75
 
68
76
    # Check if app requires auth. If so, perform authentication and login.
 
77
    # This will either return a User object, None, or perform a redirect
 
78
    # which we will not catch here.
69
79
    if app.requireauth:
70
 
        req.username = login.login(req)
71
 
        logged_in = req.username is not None
 
80
        req.user = login.login(req)
 
81
        logged_in = req.user is not None
72
82
    else:
73
 
        req.username = login.get_username(req)
 
83
        req.user = login.get_user_details(req)
74
84
        logged_in = True
75
85
 
76
86
    if logged_in:
 
87
        # Keep the user's session alive by writing to the session object.
 
88
        # req.get_session().save()
 
89
        # Well, it's a fine idea, but it creates considerable grief in the
 
90
        # concurrent update department, so instead, we'll just make the
 
91
        # sessions not time out.
 
92
        
77
93
        # If user did not specify an app, HTTP redirect to default app and
78
94
        # exit.
79
95
        if req.app is None:
80
 
            req.throw_redirect(util.make_path(conf.default_app))
 
96
            req.throw_redirect(util.make_path(conf.apps.default_app))
81
97
 
82
98
        # Set the default title to the app's tab name, if any. Otherwise URL
83
99
        # name.
110
126
    session = req.get_session()
111
127
    session.invalidate()
112
128
    session.delete()
 
129
    req.add_cookie(forumutil.invalidated_forum_cookie())
113
130
    req.throw_redirect(util.make_path(''))