X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/596ad981f61660468f9135255048754ccd7627fb..4d7f6c42629cb85f001306195c6098b4abec642a:/models/base.py diff --git a/models/base.py b/models/base.py index 202c2f3..fae385a 100644 --- a/models/base.py +++ b/models/base.py @@ -2,8 +2,9 @@ from django import forms from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic -from django.utils import simplejson as json from django.core.exceptions import ObjectDoesNotExist +from django.utils import simplejson as json +from django.utils.encoding import smart_str from philo.exceptions import AncestorDoesNotExist from philo.models.fields import JSONField from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter @@ -73,7 +74,7 @@ class JSONValue(AttributeValue): value = JSONField() #verbose_name='Value (JSON)', help_text='This value must be valid JSON.') def __unicode__(self): - return self.value_json + return smart_str(self.value) def value_formfield(self, **kwargs): kwargs['initial'] = self.value_json @@ -358,6 +359,8 @@ class TreeManager(models.Manager): if deepest_level == depth: # This should happen if nothing is found with any part of the given path. + if root is not None and deepest_found is None: + return root, build_path(segments) raise return find_obj(segments, depth, deepest_found) @@ -411,7 +414,7 @@ class TreeModel(MPTTModel): qs = self.get_ancestors() if root is not None: - qs = qs.filter(level__gt=root.level) + qs = qs.filter(**{'%s__gt' % self._mptt_meta.level_attr: root.get_level()}) return pathsep.join([getattr(parent, field, '?') for parent in list(qs) + [self]]) path = property(get_path)