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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

Old dispatch is dead - drop www/, old bits of ivle.dispatch, ivle.conf.apps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
from ivle import util
43
43
import ivle.conf
44
 
import ivle.conf.apps
45
44
from ivle.dispatch.request import Request
46
45
from ivle.dispatch import login
47
46
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
48
47
from ivle.webapp.errors import HTTPError, Unauthorized
49
 
import apps
50
48
import html
51
49
 
52
50
def generate_route_mapper(view_plugins, attr):
112
110
    conf = ivle.config.Config()
113
111
    req.config = conf
114
112
 
115
 
    ### BEGIN New plugins framework ###
116
113
    if req.publicmode:
117
114
        req.mapper = generate_route_mapper(conf.plugin_index[PublicViewPlugin],
118
115
                                           'public_urls')
164
161
            req.store.commit()
165
162
            return req.OK
166
163
    else:
167
 
        # We had no matching URL! Check if it matches an old-style app. If
168
 
        # not, 404.
169
 
        if req.app not in ivle.conf.apps.app_url:
170
 
            return req.HTTP_NOT_FOUND # TODO: Prettify.
171
 
    ### END New plugins framework ###
172
 
 
173
 
 
174
 
    ### BEGIN legacy application framework ###
175
 
    # We have no public apps back here.
176
 
    assert not req.publicmode
177
 
 
178
 
    # app is the App object for the chosen app
179
 
    if req.app is None:
180
 
        app = ivle.conf.apps.app_url[ivle.conf.apps.default_app]
181
 
    else:
182
 
        app = ivle.conf.apps.app_url[req.app]
183
 
 
184
 
    # Check if app requires auth. If so, perform authentication and login.
185
 
    # This will either return a User object, None, or perform a redirect
186
 
    # which we will not catch here.
187
 
    if app.requireauth:
188
 
        logged_in = req.user is not None
189
 
    else:
190
 
        logged_in = True
191
 
 
192
 
    assert logged_in # XXX
193
 
 
194
 
    if logged_in:
195
 
        # Keep the user's session alive by writing to the session object.
196
 
        # req.get_session().save()
197
 
        # Well, it's a fine idea, but it creates considerable grief in the
198
 
        # concurrent update department, so instead, we'll just make the
199
 
        # sessions not time out.
200
 
        req.get_session().unlock()
201
 
 
202
 
        # Call the specified app with the request object
203
 
        apps.call_app(app.dir, req)
204
 
 
205
 
    # MAKE SURE we write the HTTP (and possibly HTML) header. This
206
 
    # wouldn't happen if nothing else ever got written, so we have to make
207
 
    # sure.
208
 
    req.ensure_headers_written()
209
 
 
210
 
    # When done, write out the HTML footer if the app has requested it
211
 
    if req.write_html_head_foot:
212
 
        html.write_html_foot(req)
213
 
 
214
 
    # Note: Apache will not write custom HTML error messages here.
215
 
    # Use req.throw_error to do that.
216
 
    return req.OK
 
164
        return req.HTTP_NOT_FOUND # TODO: Prettify.
217
165
 
218
166
def handle_unknown_exception(req, exc_type, exc_value, exc_traceback):
219
167
    """