You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/09/19 20:43:27 UTC
[42/50] git commit: [#4334] ticket:158 Rewrite url dispatching for
`index.*` files
[#4334] ticket:158 Rewrite url dispatching for `index.*` files
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/c48889c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/c48889c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/c48889c7
Branch: refs/heads/master
Commit: c48889c7a9c5cdc028ed0d6d5439a46b14c1f818
Parents: 72708c0
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Aug 31 13:15:54 2012 +0300
Committer: Dave Brondsema <db...@geek.net>
Committed: Thu Sep 6 19:36:55 2012 +0000
----------------------------------------------------------------------
Allura/allura/controllers/base.py | 26 +++++++++++++++++++++++++-
Allura/allura/controllers/repository.py | 3 ++-
2 files changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c48889c7/Allura/allura/controllers/base.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/base.py b/Allura/allura/controllers/base.py
index d9b7df5..45b6162 100644
--- a/Allura/allura/controllers/base.py
+++ b/Allura/allura/controllers/base.py
@@ -1,9 +1,33 @@
from tg import expose
from webob import exc
+from tg.controllers.dispatcher import ObjectDispatcher
+
class BaseController(object):
@expose()
def _lookup(self, name, *remainder):
"""Provide explicit default lookup to avoid dispatching backtracking
and possible loops."""
- raise exc.HTTPNotFound, name
\ No newline at end of file
+ raise exc.HTTPNotFound, name
+
+
+class DispatchIndex(object):
+ """Rewrite default url dispatching for controller.
+
+ Catch url that ends with `index.*` and pass it to the `_lookup()`
+ controller method, instead of `index()` as by default.
+ Assumes that controller has `_lookup()` method.
+
+ Use default dispatching for other urls.
+
+ Use this class as a mixin to controller that needs such behaviour.
+ (see allura.controllers.repository.TreeBrowser for an example)
+ """
+ def _dispatch(self, state, remainder):
+ dispatcher = ObjectDispatcher()
+ if remainder and remainder[0] == 'index':
+ controller, new_remainder = self._lookup(*remainder)
+ state.add_controller(controller.__class__.__name__, controller)
+ dispatcher = getattr(controller, '_dispatch', dispatcher._dispatch)
+ return dispatcher(state, new_remainder)
+ return dispatcher._dispatch(state, remainder)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c48889c7/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 742e6b2..ee2ac9d 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -28,6 +28,7 @@ from allura.lib.widgets.repo import SCMMergeRequestWidget, SCMMergeRequestFilter
from allura.lib.widgets.repo import SCMMergeRequestDisposeWidget, SCMCommitBrowserWidget
from allura import model as M
from allura.lib.widgets import form_fields as ffw
+from allura.controllers.base import DispatchIndex
from .base import BaseController
@@ -439,7 +440,7 @@ class CommitBrowser(BaseController):
count=count,
**kw)
-class TreeBrowser(BaseController):
+class TreeBrowser(BaseController, DispatchIndex):
tree_widget = SCMTreeWidget()
FileBrowserClass=None