+ def handles_subpath(self, subpath):
+ return self.view.handles_subpath(subpath)
+
+ def render_to_response(self, request, extra_context=None):
+ return self.view.render_to_response(request, extra_context)
+
+ def get_absolute_url(self, request=None, with_domain=False, secure=False):
+ return self.construct_url(request=request, with_domain=with_domain, secure=secure)
+
+ def construct_url(self, subpath=None, request=None, with_domain=False, secure=False):
+ """
+ This method will construct a URL based on the Node's location.
+ If a request is passed in, that will be used as a backup in case
+ the Site lookup fails. The Site lookup takes precedence because
+ it's what's used to find the root node. This will raise:
+ - NoReverseMatch if philo-root is not reverseable
+ - Site.DoesNotExist if a domain is requested but not buildable.
+ - AncestorDoesNotExist if the root node of the site isn't an
+ ancestor of this instance.
+ """
+ # Try reversing philo-root first, since we can't do anything if that fails.
+ root_url = reverse('philo-root')
+
+ try:
+ current_site = Site.objects.get_current()
+ except Site.DoesNotExist:
+ if request is not None:
+ current_site = RequestSite(request)
+ elif with_domain:
+ # If they want a domain and we can't figure one out,
+ # best to reraise the error to let them know.
+ raise
+ else:
+ current_site = None
+
+ root = getattr(current_site, 'root_node', None)
+ path = self.get_path(root=root)
+
+ if current_site and with_domain:
+ domain = "http%s://%s" % (secure and "s" or "", current_site.domain)
+ else:
+ domain = ""
+
+ if not path:
+ subpath = subpath[1:]
+
+ return '%s%s%s%s' % (domain, root_url, path, subpath or "")