def create_app(config_name=None): if config_name is None: config_name = os.getenv('FLASK_CONFIG', 'development') app = Flask('Tblog') app.config.from_object(config[config_name]) register_extensions(app) oauth.register( name='github', client_id=app.config.get('GITHUB_CLIENT_ID'), client_secret=app.config.get('GITHUB_CLIENT_SECRET'), access_token_url='https://github.com/login/oauth/access_token', access_token_params=None, authorize_url='https://github.com/login/oauth/authorize', authorize_params=None, api_base_url='https://api.github.com/', client_kwargs={'scope': 'user:email'}, ) register_blueprints(app) register_crsf_exclude(app) register_errors(app) register_shell_context(app) register_template_context(app) register_commands(app) # register_request_handlers(app) with app.app_context(): db.create_all() return app
def initdb(drop): """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() click.echo('Initialized database.')
def init(username, email, password): """Building Tblog, just for you.""" click.echo('Initializing the database...') db.create_all() if not re.match(r"[^@]+@[^@]+\.[^@]+", email): click.echo("Email format error") return None admin = Admin.query.first() if admin is not None: click.echo('The administrator already exists, updating...') admin.username = username admin.email = email admin.set_password(password) admin.ser_api_key() else: click.echo('Creating the temporary administrator account...') admin = Admin(username=username, email=email, blog_title="Toads' Blog", blog_sub_title="Life, Programming, Miscellaneous", name='toads', about='Nothing except you!') admin.set_password(password) admin.set_api_key() 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.')
def app(): """Create and configure a new app instance for each test.""" # create the app with common test config app = create_app("testing") app.config['SECRET_KEY'] = 'testing_key' # create the database and load test data with app.app_context(): db.drop_all() db.create_all() admin = Admin(username='******', blog_title="Tests Blog", blog_sub_title="Life, Programming, Miscellaneous", name='Tests', about='Nothing except you!') admin.set_password('testpassword') admin.set_api_key() db.session.add(admin) category = Category.query.first() category = Category(name='Default') db.session.add(category) db.session.commit() yield app
def forge(category, post, comment): """Generate fake data.""" from Tblog.fakes import fake_admin, fake_categories, fake_posts, fake_comments, fake_links 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('Done.')