""" Raised by get_subpath when the View does not provide subpaths (the default). """
silent_variable_failure = True
+
class ViewCanNotProvideSubpath(Exception):
""" Raised by get_subpath when the View can not provide a subpath for the supplied object. """
- silent_variable_failure = True
\ No newline at end of file
+ silent_variable_failure = True
+
+
+class AncestorDoesNotExist(Exception):
+ """ Raised by get_path if the root model is not an ancestor of the current model """
+ pass
\ No newline at end of file
from django.contrib.contenttypes import generic
from django.utils import simplejson as json
from django.core.exceptions import ObjectDoesNotExist
+from philo.exceptions import AncestorDoesNotExist
from philo.utils import ContentTypeRegistryLimiter
from philo.signals import entity_class_prepared
from UserDict import DictMixin
return False
def get_path(self, root=None, pathsep='/', field='slug'):
- if root is not None and self.has_ancestor(root):
+ if root is not None:
+ if not self.has_ancestor(root):
+ raise AncestorDoesNotExist(root)
path = ''
parent = self
while parent and parent != root:
from philo.models.base import TreeEntity, Entity, QuerySetMapper, register_value_model
from philo.utils import ContentTypeSubclassLimiter
from philo.validators import RedirectValidator
-from philo.exceptions import ViewDoesNotProvideSubpaths
+from philo.exceptions import ViewDoesNotProvideSubpaths, AncestorDoesNotExist
_view_content_type_limiter = ContentTypeSubclassLimiter(None)
def render_to_response(self, request, path=None, subpath=None, extra_context=None):
return self.view.render_to_response(self, request, path, subpath, extra_context)
+ def get_absolute_url(self):
+ root = Site.objects.get_current().root_node
+ try:
+ return '/%s' % self.get_path(root=root)
+ except AncestorDoesNotExist:
+ return None
+
class Meta:
app_label = 'philo'
return contentlet_node_names, contentreference_node_specs
def __unicode__(self):
- return self.get_path(u' › ', 'name')
+ return self.get_path(pathsep=u' › ', field='name')
@staticmethod
@fattr(is_usable=True)