示例#1
0
 def test_validator_with_correct_tags(self):
     tag = Tag(title='a test')
     tag.save()
     validator = TagValidator()
     self.assertEqual(validator.validate_raw_string(None), True)
     self.assertEqual(validator.validate_raw_string(tag.title), True)
     self.assertEqual(validator.errors, [])
示例#2
0
 def test_validator_with_correct_tags(self):
     tag = Tag(title='a test')
     tag.save()
     validator = TagValidator()
     self.assertEqual(validator.validate_raw_string(None), True)
     self.assertEqual(validator.validate_raw_string(tag.title), True)
     self.assertEqual(validator.errors, [])
示例#3
0
    def add_tags(self, tag_collection):
        for tag in tag_collection:
            tag_title = smart_text(tag.strip().lower())
            current_tag = Tag.objects.filter(title=tag_title).first()
            if current_tag is None:
                current_tag = Tag(title=tag_title)
                current_tag.save()

            self.tags.add(current_tag)
        self.save()
示例#4
0
文件: models.py 项目: Aer-o/zds-site
    def add_tags(self,tag_collection):
        for tag in tag_collection:
            tag_title = smart_text(tag.strip().lower())
            current_tag = Tag.objects.filter(title=tag_title).first()
            if current_tag is None:
                current_tag = Tag(title=tag_title)
                current_tag.save()

            self.tags.add(current_tag)
        self.save()
示例#5
0
def load_tags(cli, size, fake):
    """
    Load tags
    """
    nb_tags = size * 50
    cli.stdout.write(u"Nombres de Tags de forum à créer : {}".format(nb_tags))
    tps1 = time.time()
    for i in range(0, nb_tags):
        title = fake.word()
        tag = Tag(title=title, slug=slugify(title))
        tag.save()
        sys.stdout.write(" Tag {}/{}  \r".format(i + 1, nb_tags))
        sys.stdout.flush()
    tps2 = time.time()
    cli.stdout.write(u"\nFait en {} sec".format(tps2 - tps1))
示例#6
0
    def add_tags(self, tag_collection):
        """
        Add all tags contained in `tag_collection` to this topic.
        If a tag is unknown, it is added to the system.
        :param tag_collection: A collection of tags.
        """
        for tag in tag_collection:
            tag_title = smart_text(tag.strip().lower())
            current_tag = Tag.objects.filter(title=tag_title).first()
            if current_tag is None:
                current_tag = Tag(title=tag_title)
                current_tag.save()

            self.tags.add(current_tag)
        self.save()
示例#7
0
 def insert_duplicated_tags(tags):
     for tag in tags:
         dupe = Tag(title=tag)
         with self.assertRaises(IntegrityError):
             with transaction.atomic():
                 dupe.save()
示例#8
0
 def insert_duplicated_tags(tags):
     for tag in tags:
         dupe = Tag(title=tag)
         with self.assertRaises(IntegrityError):
             with transaction.atomic():
                 dupe.save()