Esempio n. 1
0
    def add_tag_by_name(self, tag_name, vocab=None, autoflush=True):
        """Add a tag with the given name to this package's tags.

        By default the given tag_name will be searched for among the free tags
        (tags which do not belong to any vocabulary) only. If the optional
        argument `vocab` is given then the named vocab will be searched for the
        tag name instead.

        If no tag with the given name is found, one will be created. If the
        optional argument vocab is given and there is no tag with the given
        name in the given vocabulary, then a new tag will be created and added
        to the vocabulary.

        """
        from ckan.model.tag import Tag
        if not tag_name:
            return
        # Get the named tag.
        tag = Tag.by_name(tag_name, vocab=vocab, autoflush=autoflush)
        if not tag:
            # Tag doesn't exist yet, make a new one.
            if vocab:
                tag = Tag(name=tag_name, vocabulary_id=vocab.id)
            else:
                tag = Tag(name=tag_name)
        assert tag is not None
        self.add_tag(tag)
Esempio n. 2
0
 def update_tags(self, tags):
     tags = [t.strip(',').strip() for t in tags]
     for idea_tag in self.tags:
         if idea_tag.tag.name in tags:
             tags.remove(idea_tag.tag.name)
         else: 
             idea_tag.delete()
     for tag_name in tags:
         tag = Tag.by_name(tag_name)
         if not tag:
             tag = Tag(name=tag_name)
         idea_tag = IdeaTag(idea=self, tag=tag)
         idea_tag.add()
         self.tags.append(idea_tag)
Esempio n. 3
0
 def update_tags(self, tags):
     tags = [t.strip(',').strip() for t in tags]
     for app_tag in self.tags:
         if app_tag.tag.name in tags:
             tags.remove(app_tag.tag.name)
         else: 
             app_tag.delete()
     for tag_name in tags:
         tag = Tag.by_name(tag_name)
         if not tag:
             tag = Tag(name=tag_name)
         app_tag = ApplicationTag(application=self, tag=tag)
         app_tag.add()
         self.tags.append(app_tag)