def update_tags(self, obj, tag_names):
     """
     Update tags associated with an object.
     """
     ctype = ContentType.objects.get_for_model(obj)
     current_tags = list(self.filter(
         supertaggeditem__content_type__pk=ctype.pk,
         supertaggeditem__object_id=obj.pk
     ))
     
     updated_tag_names = parse_tag_input(tag_names)
     # Always lower case tags
     updated_tag_names = [t.lower() for t in updated_tag_names]
     
     # Process the tags with Calais
     from supertagging.modules import process
     processed_tags = process(obj, updated_tag_names)
     
     for t in updated_tag_names:
         if t not in [p.name for p in processed_tags]:
             try:
                 tags = self.filter(name__iexact=t)
                 tag = tags[0] # Take the first found tag with the same name.
             except:
                 tag = self.create(id=t, name=t, slug=slugify(t), stype='Custom')
             
             SuperTaggedItem._default_manager.get_or_create(tag=tag, content_type=ctype, object_id=obj.pk, field='None')
예제 #2
0
 def clean_name(self):
     value = self.cleaned_data['name']
     tag_names = parse_tag_input(value)
     if len(tag_names) > 1:
         raise ValidationError(_('Multiple tags were given.'))
     #elif len(tag_names[0]) > settings.MAX_TAG_LENGTH:
     #    raise forms.ValidationError(
     #        _('A tag may be no more than %s characters long.') %
     #            settings.MAX_TAG_LENGTH)
     return value