Switch to unified view

a/Allura/allura/controllers/base.py b/Allura/allura/controllers/base.py
1
from tg import expose
1
from tg import expose
2
from webob import exc
2
from webob import exc
3
from tg.controllers.dispatcher import ObjectDispatcher
4
3
5
4
class BaseController(object):
6
class BaseController(object):
5
    @expose()
7
    @expose()
6
    def _lookup(self, name, *remainder):
8
    def _lookup(self, name, *remainder):
7
        """Provide explicit default lookup to avoid dispatching backtracking
9
        """Provide explicit default lookup to avoid dispatching backtracking
8
        and possible loops."""
10
        and possible loops."""
9
        raise exc.HTTPNotFound, name
11
        raise exc.HTTPNotFound, name
12
13
14
class DispatchIndex(object):
15
    """Rewrite default url dispatching for controller.
16
17
    Catch url that ends with `index.*` and pass it to the `_lookup()`
18
    controller method, instead of `index()` as by default.
19
    Assumes that controller has `_lookup()` method.
20
21
    Use default dispatching for other urls.
22
23
    Use this class as a mixin to controller that needs such behaviour.
24
    (see allura.controllers.repository.TreeBrowser for an example)
25
    """
26
    def _dispatch(self, state, remainder):
27
        dispatcher = ObjectDispatcher()
28
        if remainder and remainder[0] == 'index':
29
            controller, new_remainder = self._lookup(*remainder)
30
            state.add_controller(controller.__class__.__name__, controller)
31
            dispatcher = getattr(controller, '_dispatch', dispatcher._dispatch)
32
            return dispatcher(state, new_remainder)
33
        return dispatcher._dispatch(state, remainder)