Ejemplo n.º 1
0
    def get_related(self, instance):
        """
        Returns all the related items
        """
        if not is_tagstar_maintained(instance):
            raise ItemNotTagstarMaintained("Item %s is not under Tagstar" % instance.__class__)

        return self.get_related_by_tags(getattr(instance, instance._tags_field_name), instance)
Ejemplo n.º 2
0
    def update_tags(self, instance, tags):
        """
        Update tags from an item
        """
        if not tags:
            return []

        if not is_tagstar_maintained(instance):
            raise ItemNotTagstarMaintained("Item %s is not under Tagstar" % instance.__class__)
        
        if is_string(tags):
            tags = string_to_list(tags)
        
        tags          = set([x.strip().lower() for x in tags])        
        instance_tags = instance._init_tags and set([ x.strip().lower() for x in instance._init_tags.split(',')]) or set()        
        
        if instance_tags != tags:          
            new_tags      = set( Tag.objects.get_or_create(name=x.strip().lower())[0] for x in (tags - instance_tags) if x.strip() )
            obsolete_tags = Tag.objects.filter(name__in=(instance_tags - tags) )
            self._add_tags(instance, new_tags)
            self._remove_tags(instance, obsolete_tags)
            
        return list(tags)