Merge branch 'release/0.9.2'
[philo.git] / philo / models / base.py
index d1dc38a..e7918f5 100644 (file)
@@ -16,23 +16,7 @@ from philo.utils.entities import AttributeMapper, TreeAttributeMapper
 from philo.validators import json_validator
 
 
 from philo.validators import json_validator
 
 
-__all__ = ('Tag', 'value_content_type_limiter', 'register_value_model', 'unregister_value_model', 'JSONValue', 'ForeignKeyValue', 'ManyToManyValue', 'Attribute', 'Entity', 'TreeEntity', 'SlugTreeEntity')
-
-
-class Tag(models.Model):
-       """A simple, generic model for tagging."""
-       #: A CharField (max length 255) which contains the name of the tag.
-       name = models.CharField(max_length=255)
-       #: A CharField (max length 255) which contains the tag's unique slug.
-       slug = models.SlugField(max_length=255, unique=True)
-       
-       def __unicode__(self):
-               """Returns the value of the :attr:`name` field"""
-               return self.name
-       
-       class Meta:
-               app_label = 'philo'
-               ordering = ('name',)
+__all__ = ('value_content_type_limiter', 'register_value_model', 'unregister_value_model', 'JSONValue', 'ForeignKeyValue', 'ManyToManyValue', 'Attribute', 'Entity', 'TreeEntity', 'SlugTreeEntity')
 
 
 #: An instance of :class:`.ContentTypeRegistryLimiter` which is used to track the content types which can be related to by :class:`ForeignKeyValue`\ s and :class:`ManyToManyValue`\ s.
 
 
 #: An instance of :class:`.ContentTypeRegistryLimiter` which is used to track the content types which can be related to by :class:`ForeignKeyValue`\ s and :class:`ManyToManyValue`\ s.
@@ -44,9 +28,6 @@ def register_value_model(model):
        value_content_type_limiter.register_class(model)
 
 
        value_content_type_limiter.register_class(model)
 
 
-register_value_model(Tag)
-
-
 def unregister_value_model(model):
        """Registers a model as a valid content type for a :class:`ForeignKeyValue` or :class:`ManyToManyValue` through the :data:`value_content_type_limiter`."""
        value_content_type_limiter.unregister_class(model)
 def unregister_value_model(model):
        """Registers a model as a valid content type for a :class:`ForeignKeyValue` or :class:`ManyToManyValue` through the :data:`value_content_type_limiter`."""
        value_content_type_limiter.unregister_class(model)
@@ -471,14 +452,15 @@ class TreeEntity(Entity, MPTTModel):
                if root == self:
                        return ''
                
                if root == self:
                        return ''
                
-               if root is None and self.is_root_node():
+               parent_id = getattr(self, "%s_id" % self._mptt_meta.parent_attr)
+               if getattr(root, 'pk', None) == parent_id:
                        return getattr(self, field, '?')
                
                if root is not None and not self.is_descendant_of(root):
                        raise AncestorDoesNotExist(root)
                
                if memoize:
                        return getattr(self, field, '?')
                
                if root is not None and not self.is_descendant_of(root):
                        raise AncestorDoesNotExist(root)
                
                if memoize:
-                       memo_args = (getattr(self, "%s_id" % self._mptt_meta.parent_attr), getattr(root, 'pk', None), pathsep, getattr(self, field, '?'))
+                       memo_args = (parent_id, getattr(root, 'pk', None), pathsep, getattr(self, field, '?'))
                        try:
                                return self._path_memo[memo_args]
                        except AttributeError:
                        try:
                                return self._path_memo[memo_args]
                        except AttributeError:
@@ -515,7 +497,7 @@ class TreeEntity(Entity, MPTTModel):
                
                """
                if mapper is None:
                
                """
                if mapper is None:
-                       if self.parent:
+                       if getattr(self, "%s_id" % self._mptt_meta.parent_attr):
                                mapper = TreeAttributeMapper
                        else:
                                mapper = AttributeMapper
                                mapper = TreeAttributeMapper
                        else:
                                mapper = AttributeMapper
@@ -542,7 +524,7 @@ class SlugTreeEntity(TreeEntity):
        path = property(get_path)
        
        def clean(self):
        path = property(get_path)
        
        def clean(self):
-               if self.parent is None:
+               if getattr(self, "%s_id" % self._mptt_meta.parent_attr) is None:
                        try:
                                self._default_manager.exclude(pk=self.pk).get(slug=self.slug, parent__isnull=True)
                        except self.DoesNotExist:
                        try:
                                self._default_manager.exclude(pk=self.pk).get(slug=self.slug, parent__isnull=True)
                        except self.DoesNotExist: