Exemplo n.º 1
0
    def init(username, password):
        """Building Bluelog, just for you."""

        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,
                          blog_title='Bluelog',
                          blog_sub_title="No, I'm the real thing.",
                          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.')
Exemplo n.º 2
0
def create_app(app_config):
    """Initialize the core application."""
    app = Flask(__name__, instance_relative_config=False)
    app.config.from_object(app_config)

    # Initialize plugins
    compress.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)

    with app.app_context():
        from blog.views import app_blueprint, error400, error404, error500

        # Register blueprints
        app.register_blueprint(app_blueprint)

        # Register error pages
        app.register_error_handler(400, error400)
        app.register_error_handler(404, error404)
        app.register_error_handler(500, error500)

        # Create database tables for our data models
        db.create_all()

        return app
Exemplo n.º 3
0
    def forge(user, follow, article, tag, comment, collect):
        """Generate fake data."""

        from blog.fakes import fake_admin, fake_user, fake_follow, fake_article, fake_tag, fake_comment, fake_collect  #fake_category,

        db.drop_all()
        db.create_all()

        click.echo('Initializing the roles and permissions...')
        Role.init_role()
        click.echo('Generating the administrator...')
        fake_admin()
        click.echo('Generating %d users...' % user)
        fake_user(user)
        click.echo('Generating %d follows...' % follow)
        fake_follow(follow)
        # click.echo('Generating %d categories...' % category)
        # fake_category(category)
        click.echo('Generating %d tags...' % tag)
        fake_tag(tag)
        click.echo('Generating %d articles...' % article)
        fake_article(article)
        click.echo('Generating %d collect...' % collect)
        fake_collect(collect)

        click.echo('Generating %d comments...' % comment)
        fake_comment(comment)
        click.echo('Done.')
Exemplo n.º 4
0
    def forge(category, post, comment):
        """Generate fake data."""
        from blog.fakes import fake_admin, fake_categories, fake_posts, fake_comments, fake_links, fake_tags

        db.drop_all()
        db.create_all()

        click.echo('Generating the administrator...')
        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('Generating links...')
        fake_links()

        click.echo('Generating tags...')
        fake_tags()

        click.echo('Generating message...')
        fake_message(count=50)

        click.echo('Generating aboutme...')
        fake_aboutme()

        click.echo('Done.')
Exemplo n.º 5
0
    def forge(category, post, book_category, book, link_category, link):
        """Generate fake data."""
        from blog.fakes import fake_categorise, fake_posts, fake_book_categorise, \
            fake_books, fake_link_categorise, fake_links

        db.drop_all()
        db.create_all()

        click.echo('Generating %d categories...' % category)
        fake_categorise(category)

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

        click.echo('Generating %d bookCategories...' % book_category)
        fake_book_categorise(book_category)

        click.echo('Generating %d books...' % book)
        fake_books(book)

        click.echo('Generating %d link_categories...' % link_category)
        fake_link_categorise(link_category)

        click.echo('Generating %d links...' % link)
        fake_links(link)

        click.echo('Done')
Exemplo n.º 6
0
 def init(username, password):
     click.echo('Initializing the database...')
     db.create_all()
     admin = Admin.query.first()
     if admin:
         click.echo('The admin already exists, updating...')
         admin.username = username
         admin.set_password(password)
     else:
         click.echo('Creating the temporary admin account...')
         admin = Admin(
             username='******',
             name='Xiaozekun',
             about='Python开发',
             blog_title='LIHFTS',
             blog_sub_title='lihfts'
         )
         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')
Exemplo n.º 7
0
 def initdb(drop):
     if drop:
         click.confirm(
             'This operation will delete the database, do you want to continue?',
             abort=True)
         db.drop_all()
     db.create_all()
     click.echo('Initialized database.')
Exemplo n.º 8
0
    def init():
        """Initialize Blog."""
        click.echo('Initializing the database...')
        db.create_all()

        click.echo('Initializing the roles and permissions...')
        Role.init_role()

        click.echo('Done.')
Exemplo n.º 9
0
def fake_admin():
    db.create_all()
    admin = Admin(username='******',
                  name='Xiaozekun',
                  about='编程工程师',
                  blog_title='我的BLOG',
                  blog_sub_title='lihfts,hhhhhhh')
    admin.set_password('1q2w3e4t5r')
    db.session.add(admin)
    db.session.commit()
Exemplo n.º 10
0
    def make_faker(num_category, num_article, num_comment):
        from blog.fake_data import fake_admin, fake_articles, fake_categories, fake_comments

        db.drop_all()
        db.create_all()
        
        fake_admin()
        fake_categories(num_category)
        fake_articles(num_article)
        fake_comments(num_comment)
Exemplo n.º 11
0
 def forge(category, post, comment):
     """Generate the fake categories, posts and commands."""
     db.drop_all()
     db.create_all()
     click.echo('Generating the admin...')
     fake_admin()
     click.echo('Generating the categories...')
     fake_categories(category)
     click.echo('Generating the posts...')
     fake_posts(post)
     click.echo('Generating the comment...')
     fake_comments(comment)
     click.echo('Done')
Exemplo n.º 12
0
def client():
    # 设置测试数据库路径和测试环境
    app = create_app('test')

    # 初始化测试数据库
    with app.test_client() as client:
        with app.app_context():
            db.drop_all()
            db.create_all()
            db.session.add(User(username='******', password='******'))
            db.session.commit()
            db.session.close()
        yield client
Exemplo n.º 13
0
    def forge(category, post):
        """Generate fake data."""
        from blog.fakes import fake_categories, fake_posts

        db.drop_all()
        db.create_all()

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

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

        click.echo('Done.')
Exemplo n.º 14
0
Arquivo: base.py Projeto: xue000/Blog
    def setUp(self):
        app = create_app('testing')
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()
        self.runner = app.test_cli_runner()

        db.create_all()
        Role.init_role()

        admin_user = User(email='*****@*****.**',
                          name='Admin',
                          username='******')
        admin_user.set_password('123')
        admin_user.set_role()
        normal_user = User(email='*****@*****.**',
                           name='Normal User',
                           username='******')
        normal_user.set_password('123')
        unconfirmed_user = User(
            email='*****@*****.**',
            name='Unconfirmed',
            username='******',
        )
        unconfirmed_user.set_password('123')
        locked_user = User(email='*****@*****.**',
                           name='Locked User',
                           username='******',
                           locked=True)
        locked_user.set_password('123')
        locked_user.lock()

        blocked_user = User(email='*****@*****.**',
                            name='Blocked User',
                            username='******',
                            active=False)
        blocked_user.set_password('123')

        category = Category(name='test category')
        post = Post(title='test post', body='Test post', category=category)
        comment = Comment(body='test comment body',
                          post=post,
                          author=normal_user)
        db.session.add_all([
            admin_user, normal_user, unconfirmed_user, locked_user,
            blocked_user
        ])
        db.session.commit()
Exemplo n.º 15
0
Arquivo: base.py Projeto: zxbylx/blog
    def setUp(self):
        app = create_app('testing')
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()
        self.runner = app.test_cli_runner()

        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()
Exemplo n.º 16
0
    def forge(category, post, comment):
        from blog.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 %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.')
Exemplo n.º 17
0
    def forge(user, post, category, comment):
        """Generate fake data."""

        from blog.fakes import fake_admin, fake_user, fake_categories, fake_post, fake_comment

        db.drop_all()
        db.create_all()

        click.echo('Initializing the roles and permissions...')
        Role.init_role()
        click.echo('Generating the administrator...')
        fake_admin()
        click.echo('Generating %d users...' % user)
        fake_user(user)
        click.echo('Generating %d categories...' % category)
        fake_categories(category)
        click.echo('Generating %d posts...' % post)
        fake_post(post)
        # click.echo('Generating %d collects...' % collect)
        # fake_collect(collect)
        click.echo('Generating %d comments...' % comment)
        fake_comment(comment)
        click.echo('Done.')
Exemplo n.º 18
0
    def init(username, password):
        """Building Bluelog, just for you."""

        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',
                blog_title='Free planets',
                blog_sub_title='頑張ってください。',
                about='anything'
            )
            admin.set_password(password)
            db.session.add(admin)
        db.session.commit()
        click.echo('Done.')
Exemplo n.º 19
0
    def init(username, password):
        click.echo('Initializing the database...')
        db.create_all()

        admin = Admin.query.first()
        if admin:
            admin.username = username
            admin.password = password
        else:
            admin = Admin(username=username,
                          blog_title='Home',
                          blog_sub_title='I can you can too',
                          name='Arvine',
                          about='I\'am on my way.')
            admin.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.')
Exemplo n.º 20
0
 def initdb(drop):
     """Initialize the database."""
     if drop:
         db.drop_all()
     db.create_all()
     click.echo('Initialized database.')
Exemplo n.º 21
0
def init_db():
    from wsgi import app
    with app.app_context():
        db.create_all()
        print('init_db! done!')