From: Stephen Burrows Date: Thu, 2 Jun 2011 14:34:11 +0000 (-0400) Subject: Added 'unique' check to SlugTreeEntity for cases where the parent is None. Set tagCre... X-Git-Tag: philo-0.9~7^2~3 X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/946f2dc5728e293dd7fc55bac7a8cf8d3dcc5722?hp=ac8a325857c260750e651281ef379d108db9ff17 Added 'unique' check to SlugTreeEntity for cases where the parent is None. Set tagCreation to create a tag if there are none left to move over. --- diff --git a/philo/models/base.py b/philo/models/base.py index 0218261..f9c22f9 100644 --- a/philo/models/base.py +++ b/philo/models/base.py @@ -1,7 +1,7 @@ from django import forms from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ValidationError from django.core.validators import RegexValidator from django.db import models from django.utils import simplejson as json @@ -522,6 +522,15 @@ class SlugTreeEntity(TreeEntity): return super(SlugTreeEntity, self).get_path(root, pathsep, field) path = property(get_path) + def clean(self): + if self.parent is None: + try: + self._default_manager.exclude(pk=self.pk).get(slug=self.slug, parent__isnull=True) + except self.DoesNotExist: + pass + else: + raise ValidationError(self.unique_error_message(self.__class__, ('parent', 'slug'))) + class Meta: unique_together = ('parent', 'slug') abstract = True \ No newline at end of file diff --git a/philo/static/philo/js/TagCreation.js b/philo/static/philo/js/TagCreation.js index 610a4f0..a23e609 100644 --- a/philo/static/philo/js/TagCreation.js +++ b/philo/static/philo/js/TagCreation.js @@ -85,6 +85,9 @@ var tagCreation = window.tagCreation; addEvent(input, 'keypress', function(e) { if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) { e.preventDefault(); + if (select.options.length == 0) { + tagCreation.addTagFromSlug(addLink); + } } }) },