Ejemplo n.º 1
0
 def save(self, *args, **kwargs):
     tag_author = self._get_default_tags_author()
     tag_lang = self._get_default_tags_language()
     self._default_tags = ", ".join(parse_tag_input(self._default_tags))
     new = not bool(self.pk)
     if not new:
         # FIXME: this two-step approach may delete tags on tags
         self.untag_all(author=tag_author)
         self.tag(self._default_tags, tag_lang, tag_author)
     super(Taggable, self).save(*args, **kwargs)
     if new:
         self.tag(self._default_tags, tag_lang, tag_author)
Ejemplo n.º 2
0
    def tag(self, name, language, author):
        """Tags this object using a `name` in a specific `language`. The tag
        will be marked as authored by `author`.

        The `name` can be a list of comma-separated tags. Double quotes can be
        used to escape values with spaces or commas. One special case: if there
        are no commas in the input, spaces are treated as tag delimiters."""
        author = _tag_get_user(author)
        language = _tag_get_language(language)
        tags = parse_tag_input(name)
        for tag_name in tags:
            tag = Tag(name=tag_name, language=language, author=author,
                content_object=self)
            tag.save()
Ejemplo n.º 3
0
    def untag_all(self, name=None, language=None, author=None):
        """untag_all([name], [language], [author])

        Untags this object from all tags in a specific `language` or authored
        by `author`."""
        author = _tag_get_user(author, default=None)
        language = _tag_get_language(language, default=None)
        ct = ContentType.objects.get_for_model(self.__class__)
        kwargs = dict(content_type=ct, object_id=self.id)
        if name is not None:
            kwargs['name__in'] = parse_tag_input(name)
        if language is not None:
            kwargs['language'] = language
        if author is not None:
            kwargs['author'] = author
        tags = Tag.objects.filter(**kwargs)
        tags.delete()
Ejemplo n.º 4
0
    def untag(self, name, language, author):
        """Untags this object from tags in a specific `language`, authored by
        `author`.

        The `name` can be a list of comma-separated tags. Double quotes can be
        used to escape values with spaces or commas. One special case: if there
        are no commas in the input, spaces are treated as tag delimiters."""
        author = _tag_get_user(author)
        language = _tag_get_language(language)
        ct = ContentType.objects.get_for_model(self.__class__)
        tags = parse_tag_input(name)
        for tag_name in tags:
            try:
                tag = Tag.objects.get(name=tag_name, language=language,
                    author=author, content_type=ct, object_id=self.id)
                tag.delete()
            except Tag.DoesNotExist:
                pass # okay, successfully "untagged".