Improve app.py
It should always create and expose the app object for uWSGI.
This commit is contained in:
parent
5d6db78e6e
commit
6282eed349
2 changed files with 16 additions and 24 deletions
33
app/app.py
33
app/app.py
|
@ -23,26 +23,9 @@ from utils import euro_string, price_range_string
|
||||||
from zeus import init_oauth
|
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:
|
def register_plugins(app: Flask) -> Manager:
|
||||||
"Register all the plugins to Haldis"
|
"Register Airbrake and logrotation plugins"
|
||||||
# pylint: disable=W0612
|
# pylint: disable=W0612
|
||||||
# Register Airbrake and enable the logrotation
|
|
||||||
if not app.debug:
|
if not app.debug:
|
||||||
timedFileHandler = TimedRotatingFileHandler(
|
timedFileHandler = TimedRotatingFileHandler(
|
||||||
app.config["LOGFILE"], when="midnight", backupCount=100
|
app.config["LOGFILE"], when="midnight", backupCount=100
|
||||||
|
@ -175,7 +158,17 @@ def add_template_filters(app: Flask) -> None:
|
||||||
app.template_filter("any")(any)
|
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
|
# For usage when you directly call the script with python
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
manager = create_app()
|
app_manager.run()
|
||||||
manager.run()
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"Script for interaction and changes to the database"
|
"Script for interaction and changes to the database"
|
||||||
import add_admins
|
import add_admins
|
||||||
from app import db, create_app
|
from app import db, app_manager
|
||||||
|
|
||||||
entry_sets = {
|
entry_sets = {
|
||||||
"admins": add_admins.add,
|
"admins": add_admins.add,
|
||||||
|
@ -69,9 +69,8 @@ def add_to_current() -> None:
|
||||||
print("Not a valid answer.")
|
print("Not a valid answer.")
|
||||||
print("Thank you for adding, come again!")
|
print("Thank you for adding, come again!")
|
||||||
|
|
||||||
manager = create_app()
|
|
||||||
|
|
||||||
@manager.command
|
@app_manager.command
|
||||||
def setup_database(): #type: None
|
def setup_database(): #type: None
|
||||||
"Start the database interaction script"
|
"Start the database interaction script"
|
||||||
print("Database modification script!")
|
print("Database modification script!")
|
||||||
|
@ -83,4 +82,4 @@ def setup_database(): #type: None
|
||||||
commit()
|
commit()
|
||||||
|
|
||||||
|
|
||||||
manager.run()
|
app_manager.run()
|
||||||
|
|
Loading…
Reference in a new issue