Пример #1
0
    def init(username, password):

        click.echo('Initializing the database...')
        db.create_all()

        admin = Admin.query.first()
        if admin is not None:
            click.echo('The administrator already exists, updating...')
            admin.username = username
            admin.set_password(password)
        else:
            click.echo('Creating the temporary administrator account...')
            admin = Admin(username=username,
                          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.')
Пример #2
0
    def init(username, password):  # 博客初始化,传入用户名和密码
        """创建BLUELOG,个性化博客"""

        click.echo('配置数据库中...')
        db.create_all()

        admin = Admin.query.first()  # 从数据库中查找管理员记录
        if admin is not None:  # 如果数据库中已经有管理员记录就更新用户名和密码
            click.echo('管理员已存在,更新中...')
            admin.username = username
            admin.set_password(
                password)  # 调用Admin模型类中的set_password()方法,生成password
        else:  # 没有管理员记录则创建新的管理员记录
            click.echo('新建管理员账户...')
            admin = Admin(username=username,
                          blog_title='Theminimize',
                          name='授我以驴',
                          about='Anything about you.')
            admin.set_password(password)
            db.session.add(admin)  # 将新创建对象添加到数据库会话

        category = Category.query.first()
        if category is None:  # 如果没有分类则创建默认分类
            click.echo('创建默认分类...')
            category = Category(name='Default')
            db.session.add(category)

        db.session.commit()  # 调用session.commit(),将改动提交到数据库
        click.echo('完成.')
Пример #3
0
 def initdb(drop):  # 初始化数据库,传入drop参数
     """初始化数据库"""
     if drop:
         click.confirm('该操作将删除原有数据库,确定删除?', abort=True)
         db.drop_all()
         click.echo('删除数据库')
     db.create_all()
     click.echo('已重置数据库')
Пример #4
0
 def initdb(drop):
     from MyBlog.fakes import fake_admin, fake_categories, fake_posts, fake_comments
     """Initialize the database."""
     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()
     fake_categories()
     click.echo('Initialized database.')
Пример #5
0
    def forge(category, post, comment):
        db.drop_all()
        db.create_all()

        click.echo('生成管理员...')
        fake_admin()

        click.echo('生成 %d 个分类...' % category)
        fake_category(category)

        click.echo('生成 %d 篇文章...' % post)
        fake_post(post)

        click.echo('生成 %d 个评论...' % comment)
        fake_comment(comment)

        click.echo('数据生成完毕!')
Пример #6
0
    def forge(post, comment):
        from MyBlog.fakes import fake_admin, fake_categories, fake_posts, fake_comments

        db.drop_all()
        db.create_all()

        click.echo('Generating the administrator...')
        fake_admin()

        click.echo('Generating categories...')
        fake_categories()

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

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

        click.echo('Done.')