示例#1
0
def fake_categories(count=10):
    category = Category(name='default')
    db.session.add(category)

    for i in range(count):
        category = Category(name=fake.word())
        db.session.add(category)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
示例#2
0
def fake_category(count=20):
    ctgy =  Category(name='Default')
    db.session.add(ctgy)
    db.session.commit()

    for i in range(count):
            ctgy = Category(name=fake.word())
            db.session.add(ctgy)
            try:
                db.session.commit()
            except:
                db.session.rollback()
示例#3
0
    def init(username, password):
        click.echo('Initializing the database...')
        db.create_all()

        admin = Admin.query.first()
        if admin:
            click.echo('The administrator already exist, updating...')
            admin.username = username
            admin.set_password(password)
        else:
            click.echo('Creating temporary administrator account...')
            admin = Admin(username=username,
                          blog_title='Blueblog',
                          blog_sub_title="I love ZAYN MALIK",
                          name='Admin',
                          about='Anything about you')
            admin.set_password(password)
            db.session.add(admin)

        category = Category.query.first()
        if category is None:
            click.echo('Creating the default category...')
            category = Category(name='Default')
            db.session.add(category)

        db.session.commit()
        click.echo('Done.')
示例#4
0
def new_category():
    form = CategoryForm()
    if form.validate_on_submit():
        name = form.name.data
        category = Category(name)
        db.session.add(category)
        db.session.commit()
        return redirect(url_for('.manage_category'))
    return render_template('admin/new_category.html', form=form)
示例#5
0
    def setUp(self):
        super(BlogTestCase, self).setUp()
        self.login()

        category = Category(name='Default')
        post = Post(title='Hello Post', category=category, body='Blah...')
        comment = Comment(body='A comment',
                          post=post,
                          from_admin=True,
                          reviewed=True)

        db.session.add_all([category, post, comment])
        db.session.commit()
示例#6
0
    def init(username, password, post, comment):
        click.echo("Initializing the databases...")

        db.drop_all()
        db.create_all()

        admin = Admin.query.first()
        if admin:
            click.echo("Admin already exists, updating...")
            admin.username = username
            admin.set_password(password)
        else:
            click.echo("Creating the admin account...")
            admin = Admin(username=username,
                          blog_title='北邮郭大宝',
                          blog_sub_title="专注大数据、机器学习",
                          name="Admin",
                          about='专注Python技术栈')
            admin.set_password(password)
            db.session.add(admin)

        category = Category.query.first()
        if category is None:
            click.echo("Creating the default category...")
            category = Category(name='默认')
            db.session.add(category)
        db.session.commit()

        from blueblog.fakes import fake_posts, fake_comments

        click.echo("Generating %d posts..." % post)
        fake_posts(post)

        click.echo("Generating %d comments..." % comment)
        fake_comments(comment)

        click.echo("Done.")