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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

  • Committer: William Grant
  • Date: 2009-03-26 06:09:54 UTC
  • mto: (1165.3.1 submissions)
  • mto: This revision was merged to the branch mainline in revision 1174.
  • Revision ID: grantw@unimelb.edu.au-20090326060954-8931c8n83xdovyiw
Split SubmitView.__init__ into new subclasses, {User,Group}SubmitView.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
import routes
41
41
 
42
42
from ivle import util
43
 
import ivle.config
 
43
import ivle.conf
44
44
from ivle.dispatch.request import Request
45
45
import ivle.webapp.security
46
46
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
47
47
from ivle.webapp.base.xhtml import XHTMLView, XHTMLErrorView
48
48
from ivle.webapp.errors import HTTPError, Unauthorized, NotFound
49
49
 
50
 
config = ivle.config.Config()
51
 
 
52
 
def generate_router(view_plugins, attr):
 
50
def generate_route_mapper(view_plugins, attr):
53
51
    """
54
52
    Build a Mapper object for doing URL matching using 'routes', based on the
55
53
    given plugin registry.
73
71
    @param apachereq: An Apache request object.
74
72
    """
75
73
    # Make the request object into an IVLE request which can be given to views
76
 
    req = Request(apachereq, config)
 
74
    req = Request(apachereq)
77
75
 
78
76
    # Hack? Try and get the user login early just in case we throw an error
79
77
    # (most likely 404) to stop us seeing not logged in even when we are.
84
82
        if user and user.valid:
85
83
            req.user = user
86
84
 
 
85
    conf = ivle.config.Config()
 
86
    req.config = conf
 
87
 
87
88
    if req.publicmode:
88
 
        req.mapper = generate_router(config.plugin_index[PublicViewPlugin],
89
 
                                    'public_urls')
 
89
        req.mapper = generate_route_mapper(conf.plugin_index[PublicViewPlugin],
 
90
                                           'public_urls')
90
91
    else:
91
 
        req.mapper = generate_router(config.plugin_index[ViewPlugin], 'urls')
 
92
        req.mapper = generate_route_mapper(conf.plugin_index[ViewPlugin],
 
93
                                           'urls')
92
94
 
93
95
    matchdict = req.mapper.match(req.uri)
94
96
    if matchdict is not None:
153
155
    the IVLE request is created.
154
156
    """
155
157
    req.content_type = "text/html"
156
 
    logfile = os.path.join(config['paths']['logs'], 'ivle_error.log')
 
158
    logfile = os.path.join(ivle.conf.log_path, 'ivle_error.log')
157
159
    logfail = False
158
 
    req.status = mod_python.apache.HTTP_INTERNAL_SERVER_ERROR
159
 
 
 
160
    try:
 
161
        httpcode = exc_value.httpcode
 
162
        req.status = httpcode
 
163
    except AttributeError:
 
164
        httpcode = None
 
165
        req.status = mod_python.apache.HTTP_INTERNAL_SERVER_ERROR
160
166
    try:
161
167
        publicmode = req.publicmode
162
168
    except AttributeError:
185
191
    # misbehaves (which is currently very easy, if things aren't set up
186
192
    # correctly).
187
193
    # Write the traceback.
188
 
 
189
 
    # We need to special-case IVLEJailError, as we can get another
 
194
    # If this is a non-4xx IVLEError, get the message and httpcode and
 
195
    # make the error message a bit nicer (but still include the
 
196
    # traceback).
 
197
    # We also need to special-case IVLEJailError, as we can get another
190
198
    # almost-exception out of it.
 
199
 
 
200
    codename, msg = None, None
 
201
 
191
202
    if exc_type is util.IVLEJailError:
 
203
        msg = exc_value.type_str + ": " + exc_value.message
192
204
        tb = 'Exception information extracted from IVLEJailError:\n'
193
205
        tb += urllib.unquote(exc_value.info)
194
206
    else:
 
207
        try:
 
208
            codename, msg = req.get_http_codename(httpcode)
 
209
        except AttributeError:
 
210
            pass
 
211
 
195
212
        tb = ''.join(traceback.format_exception(exc_type, exc_value,
196
213
                                                exc_traceback))
197
214
 
198
 
    logging.error('\n' + tb)
 
215
    logging.error('%s\n%s'%(str(msg), tb))
199
216
 
200
217
    # Error messages are only displayed is the user is NOT a student,
201
218
    # or if there has been a problem logging the error message
205
222
<html xmlns="http://www.w3.org/1999/xhtml">
206
223
<head><title>IVLE Internal Server Error</title></head>
207
224
<body>
208
 
<h1>IVLE Internal Server Error</h1>
 
225
<h1>IVLE Internal Server Error""")
 
226
    if show_errors:
 
227
        if codename is not None and \
 
228
           httpcode != mod_python.apache.HTTP_INTERNAL_SERVER_ERROR:
 
229
            req.write(": %s" % cgi.escape(codename))
 
230
 
 
231
    req.write("""</h1>
209
232
<p>An error has occured which is the fault of the IVLE developers or
210
233
administrators. """)
211
234
 
217
240
    req.write("</p>")
218
241
 
219
242
    if show_errors:
 
243
        if msg is not None:
 
244
            req.write("<p>%s</p>\n" % cgi.escape(msg))
 
245
        if httpcode is not None:
 
246
            req.write("<p>(HTTP error code %d)</p>\n" % httpcode)
220
247
        req.write("<h2>Debugging information</h2>")
 
248
 
221
249
        req.write("<pre>\n%s\n</pre>\n"%cgi.escape(tb))
222
250
    req.write("</body></html>")