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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

  • Committer: William Grant
  • Date: 2010-07-28 05:06:15 UTC
  • Revision ID: grantw@unimelb.edu.au-20100728050615-uwbxn9frla3pdw8m
Encode content_type when downloading files. cjson made us write bad code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
    # Make the request object into an IVLE request which can be given to views
127
127
    req = Request(apachereq, config)
128
128
 
129
 
    # Hack? Try and get the user login early just in case we throw an error
130
 
    # (most likely 404) to stop us seeing not logged in even when we are.
131
 
    if not req.publicmode:
132
 
        user = ivle.webapp.security.get_user_details(req)
133
 
 
134
 
        # Don't set the user if it is disabled or hasn't accepted the ToS.
135
 
        if user and user.valid:
136
 
            req.user = user
137
 
 
138
129
    req.publisher = generate_publisher(
139
 
        config.plugin_index[ViewPlugin],
140
 
        ApplicationRoot(req.config, req.store, req.user),
 
130
        config.plugin_index[ViewPlugin], ApplicationRoot(req),
141
131
        publicmode=req.publicmode)
142
132
 
143
133
    try:
201
191
            handle_unknown_exception(req, *sys.exc_info())
202
192
            return req.OK
203
193
        else:
204
 
            req.store.commit()
 
194
            # Commit the transaction if we have a store open.
 
195
            req.commit()
205
196
            return req.OK
206
197
    except Unauthorized, e:
207
198
        # Resolution failed due to a permission check. Display a pretty
219
210
 
220
211
        return req.OK
221
212
    finally:
222
 
        req.store.close()
 
213
        # Make sure we close the store.
 
214
        req.cleanup()
223
215
 
224
216
def handle_unknown_exception(req, exc_type, exc_value, exc_traceback):
225
217
    """
235
227
    logfile = os.path.join(config['paths']['logs'], 'ivle_error.log')
236
228
    logfail = False
237
229
 
238
 
    # XXX: This remains here for ivle.interpret's IVLEErrors. Once we rewrite
239
 
    #      fileservice, req.status should always be 500 (ISE) here.
240
 
    try:
241
 
        httpcode = exc_value.httpcode
242
 
        req.status = httpcode
243
 
    except AttributeError:
244
 
        httpcode = None
245
 
        req.status = mod_python.apache.HTTP_INTERNAL_SERVER_ERROR
 
230
    req.status = mod_python.apache.HTTP_INTERNAL_SERVER_ERROR
246
231
 
247
232
    try:
248
233
        publicmode = req.publicmode