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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

  • Committer: Matt Giuca
  • Date: 2009-03-24 03:14:44 UTC
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: matt.giuca@gmail.com-20090324031444-dbpn1bj6dr4zh4sx
Added auto-generated (and hand-modified) Sphinx files (conf, Makefile and
    index).
    Our IVLE documentation will be stored as Sphinx files.
    make html to generate the documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
from ivle.webapp.errors import HTTPError, Unauthorized
 
47
from ivle.webapp.base.xhtml import XHTMLView, XHTMLErrorView
 
48
from ivle.webapp.errors import HTTPError, Unauthorized, NotFound
48
49
 
49
50
def generate_route_mapper(view_plugins, attr):
50
51
    """
116
117
            if hasattr(viewcls, 'get_error_view'):
117
118
                errviewcls = viewcls.get_error_view(e)
118
119
            else:
119
 
                errviewcls = None
 
120
                errviewcls = XHTMLView.get_error_view(e)
120
121
 
121
122
            if errviewcls:
122
123
                errview = errviewcls(req, e)
127
128
                return req.OK
128
129
            else:
129
130
                return e.code
 
131
        except mod_python.apache.SERVER_RETURN:
 
132
            # A mod_python-specific Apache error.
 
133
            # XXX: We need to raise these because req.throw_error() uses them.
 
134
            # Remove this after Google Code issue 117 is fixed.
 
135
            raise
130
136
        except Exception, e:
131
137
            # A non-HTTPError appeared. We have an unknown exception. Panic.
132
138
            handle_unknown_exception(req, *sys.exc_info())
135
141
            req.store.commit()
136
142
            return req.OK
137
143
    else:
138
 
        return req.HTTP_NOT_FOUND # TODO: Prettify.
 
144
        XHTMLErrorView(req, NotFound()).render(req)
 
145
        return req.OK
139
146
 
140
147
def handle_unknown_exception(req, exc_type, exc_value, exc_traceback):
141
148
    """
164
171
        login = req.user.login
165
172
    except AttributeError:
166
173
        login = None
167
 
    try:
168
 
        role = req.user.role
169
 
    except AttributeError:
170
 
        role = None
171
174
 
172
175
    # Log File
173
176
    try:
213
216
 
214
217
    # Error messages are only displayed is the user is NOT a student,
215
218
    # or if there has been a problem logging the error message
216
 
    show_errors = (not publicmode) and ((login and \
217
 
                        str(role) != "student") or logfail)
 
219
    show_errors = (not publicmode) and ((login and req.user.admin) or logfail)
218
220
    req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"                 
219
221
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">                                      
220
222
<html xmlns="http://www.w3.org/1999/xhtml">