示例#1
0
 def remove_tag(self, tag, auth, save=True, log=True):
     from website.models import Tag, NodeLog  # Prevent import error
     tag = Tag.load(tag)
     if tag and tag in self.tags and not self.node.is_registration:
         self.tags.remove(tag)
         if log:
             self.add_tag_log(NodeLog.FILE_TAG_REMOVED, tag._id, auth)
         if save:
             self.save()
         return True
     return False
示例#2
0
 def remove_tag(self, tag, auth, save=True, log=True):
     from website.models import Tag, NodeLog  # Prevent import error
     tag = Tag.load(tag)
     if tag and tag in self.tags and not self.node.is_registration:
         self.tags.remove(tag)
         if log:
             self.add_tag_log(NodeLog.FILE_TAG_REMOVED, tag._id, auth)
         if save:
             self.save()
         return True
     return False
示例#3
0
 def add_tag(self, tag, auth, save=True, log=True):
     from website.models import Tag, NodeLog  # Prevent import error
     if tag not in self.tags and not self.node.is_registration:
         new_tag = Tag.load(tag)
         if not new_tag:
             new_tag = Tag(_id=tag)
         new_tag.save()
         self.tags.append(new_tag)
         if log:
             self.add_tag_log(NodeLog.FILE_TAG_ADDED, tag, auth)
         if save:
             self.save()
         return True
     return False
示例#4
0
def verify_tags(node, modm_node):
    modm_tag_keys = [x for x in sorted(set(modm_node.tags._to_primary_keys())) if MODMTag.load(x)]
    django_tag_keys = sorted(set(node.tags.filter(
        system=False).values_list('_id',
                                  flat=True)))
    modm_system_tag_keys = sorted(set(modm_node.system_tags))
    django_system_tag_keys = sorted(set(
        node.system_tags.values_list('_id',
                                     flat=True)))

    assert modm_tag_keys == django_tag_keys, 'Modm tags {} don\'t match django tags {} in node {}:{}'.format(
        modm_tag_keys, django_tag_keys, modm_node._id, node._guid.guid)
    assert modm_system_tag_keys == django_system_tag_keys, 'Modm system tag keys {} don\'t match django system tags {}'.format(
        modm_system_tag_keys, django_system_tag_keys)
示例#5
0
 def add_tag(self, tag, auth, save=True, log=True):
     from website.models import Tag, NodeLog  # Prevent import error
     if tag not in self.tags and not self.node.is_registration:
         new_tag = Tag.load(tag)
         if not new_tag:
             new_tag = Tag(_id=tag)
         new_tag.save()
         self.tags.append(new_tag)
         if log:
             self.add_tag_log(NodeLog.FILE_TAG_ADDED, tag, auth)
         if save:
             self.save()
         return True
     return False
示例#6
0
def verify_tags(node, modm_node):
    modm_tag_keys = [
        x for x in sorted(set(modm_node.tags._to_primary_keys()))
        if MODMTag.load(x)
    ]
    django_tag_keys = sorted(
        set(node.tags.filter(system=False).values_list('_id', flat=True)))
    modm_system_tag_keys = sorted(set(modm_node.system_tags))
    django_system_tag_keys = sorted(
        set(node.system_tags.values_list('_id', flat=True)))

    assert modm_tag_keys == django_tag_keys, 'Modm tags {} don\'t match django tags {} in node {}:{}'.format(
        modm_tag_keys, django_tag_keys, modm_node._id, node._guid.guid)
    assert modm_system_tag_keys == django_system_tag_keys, 'Modm system tag keys {} don\'t match django system tags {}'.format(
        modm_system_tag_keys, django_system_tag_keys)
示例#7
0
    def remove_tag(self, tag, auth, save=True, log=True):
        from website.models import Tag, NodeLog  # Prevent import error
        if self.node.is_registration:
            # Can't perform edits on a registration
            raise NodeStateError

        tag = Tag.load(tag)
        if not tag:
            raise InvalidTagError
        elif tag not in self.tags:
            raise TagNotFoundError
        else:
            self.tags.remove(tag)
            if log:
                self.add_tag_log(NodeLog.FILE_TAG_REMOVED, tag._id, auth)
            if save:
                self.save()
            return True
示例#8
0
    def remove_tag(self, tag, auth, save=True, log=True):
        from website.models import Tag, NodeLog  # Prevent import error
        if self.node.is_registration:
            # Can't perform edits on a registration
            raise NodeStateError

        tag = Tag.load(tag)
        if not tag:
            raise InvalidTagError
        elif tag not in self.tags:
            raise TagNotFoundError
        else:
            self.tags.remove(tag)
            if log:
                self.add_tag_log(NodeLog.FILE_TAG_REMOVED, tag._id, auth)
            if save:
                self.save()
            return True