Esempio n. 1
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.')
Esempio n. 2
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.')
Esempio n. 3
0
    def setUp(self):
        app = create_app('testing')
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()

        db.create_all()
        user = Admin(name='Grey Li', username='******', about='I am test', blog_title='Testlog', blog_sub_title='a test')
        user.set_password('123')
        db.session.add(user)
        db.session.commit()
Esempio n. 4
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.")
Esempio n. 5
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.")