Use factory strategy.

This commit is contained in:
Alexis Lahouze 2017-05-13 10:31:17 +02:00
parent 49197e61ef
commit 666ef171d8
2 changed files with 33 additions and 18 deletions

View File

@ -24,25 +24,35 @@ from flask_alembic import alembic_click
from .models import db
from .views import api, cors
# The app
app = Flask(__name__, static_folder=None, template_folder=None)
# Configure it from config.cfg.
app.config.from_pyfile('config.cfg')
app.config['SQLALCHEMY_ECHO'] = app.debug
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db.init_app(app)
# Database migrations.
alembic = Alembic(app)
# pylint: disable=invalid-name
alembic = Alembic()
def create_app(config_path):
"""Create the app using specific config file."""
# The app
app = Flask(__name__, static_folder=None, template_folder=None)
# Configure it from configuration file.
app.config.from_pyfile(config_path)
# Database related stuff.
app.config['SQLALCHEMY_ECHO'] = app.debug
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
db.init_app(app)
app.config['ALEMBIC'] = {
'script_location': 'migrations'
}
alembic.init_app(app)
# API views related stuff.
cors.init_app(app)
api.init_app(app)
return app
# Database initialization.
@ -62,7 +72,3 @@ def dropdb():
click.echo("Clearing database.")
db.metadata.drop_all(bind=db.engine)
click.echo("Database cleared.")
api.init_app(app)
cors.init_app(app)

9
accountant/run.py Normal file
View File

@ -0,0 +1,9 @@
"""Accountant runner."""
from os import path, getcwd
from . import create_app
config_path = path.join(getcwd(), 'config.cfg') # pylint: disable=invalid-name
app = create_app(config_path) # pylint: disable=invalid-name