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

« back to all changes in this revision

Viewing changes to www/dispatch/__init__.py

  • Committer: mattgiuca
  • Date: 2008-01-31 01:10:29 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:344
dispatch/ivle CSS foo.
The IVLE header is now a fixed height in em (previously was just intrinsic
    height).
This fixes the "tabs sometimes don't line up with the base line" display
problem, and also makes it much easier to add fixed or absolute content on the
rest of the page.

This was done by separating the tabs out into a separate div and making that
absolutely positioned. Now the header is exactly 5.3em.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
from request import Request
39
39
import html
 
40
import login
40
41
from common import util
41
42
 
42
43
def handler(req):
51
52
 
52
53
    # Check req.app to see if it is valid. 404 if not.
53
54
    if req.app is not None and req.app not in conf.apps.app_url:
54
 
        # TODO: Nicer 404 message?
55
 
        req.throw_error(Request.HTTP_NOT_FOUND)
 
55
        # Maybe it is a special app!
 
56
        if req.app == 'logout':
 
57
            logout(req)
 
58
        else:
 
59
            # TODO: Nicer 404 message?
 
60
            req.throw_error(Request.HTTP_NOT_FOUND)
 
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
56
69
 
57
70
    # app is the App object for the chosen app
58
71
    if req.app is None:
59
 
        app = conf.apps.app_url[conf.default_app]
 
72
        app = conf.apps.app_url[conf.apps.default_app]
60
73
    else:
61
74
        app = conf.apps.app_url[req.app]
62
75
 
63
76
    # Check if app requires auth. If so, perform authentication and login.
64
77
    if app.requireauth:
65
 
        # TODO: Perform authentication
66
 
        pass
67
 
 
68
 
    # If user did not specify an app, HTTP redirect to default app and exit.
69
 
    if req.app is None:
70
 
        req.throw_redirect(util.make_path(conf.default_app))
71
 
 
72
 
    # Set the default title to the app's tab name, if any. Otherwise URL name.
73
 
    if app.name is not None:
74
 
        req.title = app.name
 
78
        req.username = login.login(req)
 
79
        logged_in = req.username is not None
75
80
    else:
76
 
        req.title = req.app
77
 
 
78
 
    # Call the specified app with the request object
79
 
    apps.call_app(app.dir, req)
 
81
        req.username = login.get_username(req)
 
82
        logged_in = True
 
83
 
 
84
    if logged_in:
 
85
        # Keep the user's session alive by writing to the session object.
 
86
        req.get_session().save()
 
87
        # If user did not specify an app, HTTP redirect to default app and
 
88
        # exit.
 
89
        if req.app is None:
 
90
            req.throw_redirect(util.make_path(conf.apps.default_app))
 
91
 
 
92
        # Set the default title to the app's tab name, if any. Otherwise URL
 
93
        # name.
 
94
        if app.name is not None:
 
95
            req.title = app.name
 
96
        else:
 
97
            req.title = req.app
 
98
 
 
99
        # Call the specified app with the request object
 
100
        apps.call_app(app.dir, req)
 
101
    # if not logged in, login.login will have written the login box.
 
102
    # Just clean up and exit.
80
103
 
81
104
    # MAKE SURE we write the HTTP (and possibly HTML) header. This
82
105
    # wouldn't happen if nothing else ever got written, so we have to make
87
110
    if req.write_html_head_foot:
88
111
        html.write_html_foot(req)
89
112
 
90
 
    # Have Apache output its own HTML code if non-200 status codes were found
91
 
    return req.status
 
113
    # Note: Apache will not write custom HTML error messages here.
 
114
    # Use req.throw_error to do that.
 
115
    return req.OK
92
116
 
 
117
def logout(req):
 
118
    """Log out the current user (if any) by destroying the session state.
 
119
    Then redirect to the top-level IVLE page."""
 
120
    session = req.get_session()
 
121
    session.invalidate()
 
122
    session.delete()
 
123
    req.throw_redirect(util.make_path(''))