Beispiel #1
0
 def initdb(drop):
     if drop:
         click.confirm(
             'This operation will delete the database, do you want to continue?',
             abort=True)
         db.drop_all()
         click.echo('Drop tables.')
     db.create_all()
     click.echo('Initialized database.')
Beispiel #2
0
    def forge(category, post, comment):
        from blueblog.fakes import fake_admin, fake_categories, fake_comments, fake_posts

        db.drop_all()
        db.create_all()

        click.echo("Generating the admin...")
        fake_admin()

        click.echo("Generating %d categories..." % category)
        fake_categories(category)

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

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

        click.echo("Done.")
Beispiel #3
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.")
Beispiel #4
0
 def tearDown(self):
     db.drop_all()
     self.context.pop()