From 8fff8672235eafa1cf55739d460119b3be5faf5f Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Wed, 16 Mar 2011 16:33:47 -0400 Subject: [PATCH] Corrected node_view redirection of trailing slashes to non-trailing slashes to rely on request._cached_node_path instead of request.path. Tweaked LazyNode to only return a found node if it handles the found subpath. --- middleware.py | 8 +++++++- urls.py | 2 +- views.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/middleware.py b/middleware.py index c0b1e9e..5bcd569 100644 --- a/middleware.py +++ b/middleware.py @@ -24,6 +24,9 @@ class LazyNode(object): node, subpath = Node.objects.get_with_path(path, root=getattr(current_site, 'root_node', None), absolute_result=False) except Node.DoesNotExist: node = None + else: + if subpath and not node.handles_subpath(subpath): + node = None if node: if subpath is None: @@ -46,7 +49,10 @@ class RequestNodeMiddleware(object): request.__class__.node = LazyNode() def process_view(self, request, view_func, view_args, view_kwargs): - request._cached_node_path = view_kwargs.get('path', '/') + try: + request._cached_node_path = view_kwargs['path'] + except KeyError: + pass def process_exception(self, request, exception): if settings.DEBUG or not hasattr(request, 'node') or not request.node: diff --git a/urls.py b/urls.py index 47be7da..0363224 100644 --- a/urls.py +++ b/urls.py @@ -3,6 +3,6 @@ from philo.views import node_view urlpatterns = patterns('', - url(r'^$', node_view, name='philo-root'), + url(r'^$', node_view, kwargs={'path': '/'}, name='philo-root'), url(r'^(?P.*)$', node_view, name='philo-node-by-path') ) diff --git a/views.py b/views.py index f5a2c7f..598be36 100644 --- a/views.py +++ b/views.py @@ -28,7 +28,7 @@ def node_view(request, path=None, **kwargs): subpath = request.node.subpath # Explicitly disallow trailing slashes if we are otherwise at a node's url. - if request.path and request.path != "/" and request.path[-1] == "/" and subpath == "/": + if request._cached_node_path != "/" and request._cached_node_path[-1] == "/" and subpath == "/": return HttpResponseRedirect(node.get_absolute_url()) if not node.handles_subpath(subpath): -- 2.20.1