-class LazyNode(object):
- def __get__(self, request, obj_type=None):
- if not hasattr(request, '_cached_node_path'):
- return None
-
- if not hasattr(request, '_found_node'):
- try:
- current_site = Site.objects.get_current()
- 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(path, root=getattr(current_site, 'root_node', None), absolute_result=False)
- except Node.DoesNotExist:
- node = None
- else:
- if subpath is None:
- subpath = ""
- subpath = "/" + subpath
-
- if not node.handles_subpath(subpath):
- node = None
- else:
- if trailing_slash and subpath[-1] != "/":
- subpath += "/"
-
- node.subpath = subpath
-
- request._found_node = node
-
- return request._found_node
+def get_node(path):
+ """Returns a :class:`Node` instance at ``path`` (relative to the current site) or ``None``."""
+ try:
+ current_site = Site.objects.get_current()
+ except Site.DoesNotExist:
+ current_site = None
+
+ trailing_slash = False
+ if path[-1] == '/':
+ trailing_slash = True
+
+ try:
+ node, subpath = Node.objects.get_with_path(path, root=getattr(current_site, 'root_node', None), absolute_result=False)
+ except Node.DoesNotExist:
+ return None
+
+ if subpath is None:
+ subpath = ""
+ subpath = "/" + subpath
+
+ if trailing_slash and subpath[-1] != "/":
+ subpath += "/"
+
+ node._path = path
+ node._subpath = subpath
+
+ return node