Beispiel #1
0
def generate_tags(n):
    tags = list()
    for i in range(n):
        tag = Tag(faker.color_name())
        tag.title = faker.color_name()
        try:
            db.session.add(tag)
            db.session.commit()
            tags.append(tag)
        except Exception as e:
            log.error("Fail to add tag %s: %s" % (str(tag), e))
            db.session.rollback()
    return tags
Beispiel #2
0
for title, tag in items:
    c = Community()
    c.name = slugify(title)
    c.description = title
    c.maintainer = me

    with database.atomic():
        try:
            c.save()
        except peewee.IntegrityError as e:
            pass

    c = Community.get(Community.name == slugify(title))

    t = Tag()
    t.title = tag
    t.community = c

    with database.atomic():
        try:
            t.save()
        except peewee.IntegrityError as e:
            pass

    continue

    for z in range(0, 5):
        p = Proposal()
        p.title = fake.sentence(nb_words=5, variable_nb_words=False)
        p.author = get_random_user()
        p.community = c