Tweaked LazyNode to handle trailing slashes. Corrected missing import in models/nodes.py.
authorStephen Burrows <stephen.r.burrows@gmail.com>
Fri, 4 Feb 2011 02:18:08 +0000 (21:18 -0500)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Fri, 4 Feb 2011 02:18:08 +0000 (21:18 -0500)
middleware.py
models/nodes.py

index fa30ef6..c0b1e9e 100644 (file)
@@ -15,8 +15,13 @@ class LazyNode(object):
                        except Site.DoesNotExist:
                                current_site = None
                        
+                       path = request._cached_node_path
+                       trailing_slash = False
+                       if path[-1] == '/':
+                               trailing_slash = True
+                       
                        try:
-                               node, subpath = Node.objects.get_with_path(request._cached_node_path, root=getattr(current_site, 'root_node', None), absolute_result=False)
+                               node, subpath = Node.objects.get_with_path(path, root=getattr(current_site, 'root_node', None), absolute_result=False)
                        except Node.DoesNotExist:
                                node = None
                        
@@ -24,6 +29,10 @@ class LazyNode(object):
                                if subpath is None:
                                        subpath = ""
                                subpath = "/" + subpath
+                               
+                               if trailing_slash and subpath[-1] != "/":
+                                       subpath += "/"
+                               
                                node.subpath = subpath
                        
                        request._found_node = node
index 8d33d43..09376b8 100644 (file)
@@ -3,6 +3,7 @@ from django.contrib.contenttypes.models import ContentType
 from django.contrib.contenttypes import generic
 from django.contrib.sites.models import Site, RequestSite
 from django.http import HttpResponse, HttpResponseServerError, HttpResponseRedirect, Http404
+from django.core.exceptions import ValidationError
 from django.core.servers.basehttp import FileWrapper
 from django.core.urlresolvers import resolve, clear_url_caches, reverse, NoReverseMatch
 from django.template import add_to_builtins as register_templatetags