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

« back to all changes in this revision

Viewing changes to www/dispatch/__init__.py

  • Committer: mattgiuca
  • Date: 2007-12-21 01:30:40 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:114
setup.py: Wrote listmake (and ancillary functions).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# IVLE
 
2
# Copyright (C) 2007-2008 The University of Melbourne
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
# Module: dispatch
 
19
# Author: Matt Giuca
 
20
# Date: 11/12/2007
 
21
 
 
22
# This is a mod_python handler program. The correct way to call it is to have
 
23
# Apache send all requests to be handled by the module 'dispatch'.
 
24
 
 
25
# Top-level handler. Handles all requests to all pages in IVLE.
 
26
# Handles authentication (not authorization).
 
27
# Then passes the request along to the appropriate ivle app.
 
28
 
 
29
import mod_python
 
30
from mod_python import apache
 
31
 
 
32
import os
 
33
import os.path
 
34
import conf
 
35
import conf.apps
 
36
import apps
 
37
 
 
38
from request import Request
 
39
import html
 
40
from common import util
 
41
 
 
42
def handler(req):
 
43
    """Handles a request which may be to anywhere in the site except media.
 
44
    Intended to be called by mod_python, as a handler.
 
45
 
 
46
    req: An Apache request object.
 
47
    """
 
48
    # Make the request object into an IVLE request which can be passed to apps
 
49
    apachereq = req
 
50
    req = Request(req, html.write_html_head)
 
51
 
 
52
    # Check req.app to see if it is valid. 404 if not.
 
53
    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)
 
56
 
 
57
    # app is the App object for the chosen app
 
58
    if req.app is None:
 
59
        app = conf.apps.app_url[conf.default_app]
 
60
    else:
 
61
        app = conf.apps.app_url[req.app]
 
62
 
 
63
    # Check if app requires auth. If so, perform authentication and login.
 
64
    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
 
75
    else:
 
76
        req.title = req.app
 
77
 
 
78
    # Call the specified app with the request object
 
79
    apps.call_app(app.dir, req)
 
80
 
 
81
    # MAKE SURE we write the HTTP (and possibly HTML) header. This
 
82
    # wouldn't happen if nothing else ever got written, so we have to make
 
83
    # sure.
 
84
    req.ensure_headers_written()
 
85
 
 
86
    # When done, write out the HTML footer if the app has requested it
 
87
    if req.write_html_head_foot:
 
88
        html.write_html_foot(req)
 
89
 
 
90
    # Have Apache output its own HTML code if non-200 status codes were found
 
91
    return req.status
 
92