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.core.validators import RegexValidator
+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
class Meta:
app_label = 'philo'
+ ordering = ('name',)
class Titled(models.Model):
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
value_object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True)
value = generic.GenericForeignKey('value_content_type', 'value_object_id')
- key = models.CharField(max_length=255)
+ key = models.CharField(max_length=255, validators=[RegexValidator("\w+")], help_text="Must contain one or more alphanumeric characters or underscores.")
def __unicode__(self):
return u'"%s": %s' % (self.key, self.value)
if deepest_level == depth:
# This should happen if nothing is found with any part of the given path.
- if root is not None:
+ if root is not None and deepest_found is None:
return root, build_path(segments)
raise
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)