Improve app.py

It should always create and expose the app object for uWSGI.
This commit is contained in:
Midgard 2020-06-22 19:22:47 +02:00
parent 5d6db78e6e
commit 6282eed349
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 16 additions and 24 deletions

View file

@ -23,26 +23,9 @@ from utils import euro_string, price_range_string
from zeus import init_oauth
def create_app() -> Manager:
"Create the Haldis application"
app = Flask(__name__)
# Load the config file
app.config.from_object("config.Configuration")
app_manager = register_plugins(app)
add_handlers(app)
add_routes(app)
add_template_filters(app)
# TODO do we need to return and then run the manager?
return app_manager
def register_plugins(app: Flask) -> Manager:
"Register all the plugins to Haldis"
"Register Airbrake and logrotation plugins"
# pylint: disable=W0612
# Register Airbrake and enable the logrotation
if not app.debug:
timedFileHandler = TimedRotatingFileHandler(
app.config["LOGFILE"], when="midnight", backupCount=100
@ -175,7 +158,17 @@ def add_template_filters(app: Flask) -> None:
app.template_filter("any")(any)
app = Flask(__name__)
# Load the config file
app.config.from_object("config.Configuration")
app_manager = register_plugins(app)
add_handlers(app)
add_routes(app)
add_template_filters(app)
# For usage when you directly call the script with python
if __name__ == "__main__":
manager = create_app()
manager.run()
app_manager.run()

View file

@ -1,6 +1,6 @@
"Script for interaction and changes to the database"
import add_admins
from app import db, create_app
from app import db, app_manager
entry_sets = {
"admins": add_admins.add,
@ -69,9 +69,8 @@ def add_to_current() -> None:
print("Not a valid answer.")
print("Thank you for adding, come again!")
manager = create_app()
@manager.command
@app_manager.command
def setup_database(): #type: None
"Start the database interaction script"
print("Database modification script!")
@ -83,4 +82,4 @@ def setup_database(): #type: None
commit()
manager.run()
app_manager.run()