2021-05-25 19:01:20 +00:00
|
|
|
""" flask apps initialisation """
|
|
|
|
import logging
|
2021-05-26 11:55:22 +00:00
|
|
|
from logging.handlers import TimedRotatingFileHandler
|
2021-05-25 19:01:20 +00:00
|
|
|
from flask import Flask
|
|
|
|
from pony.flask import Pony
|
|
|
|
from ITPlanning.api import api
|
2021-05-26 11:55:56 +00:00
|
|
|
from ITPlanning.db import init_database
|
2021-05-26 11:55:22 +00:00
|
|
|
from ITPlanning.config import IniConfig
|
2021-05-26 11:56:20 +00:00
|
|
|
from ITPlanning.frontend import frontend
|
|
|
|
|
2021-05-26 11:55:22 +00:00
|
|
|
logger = logging.getLogger("ITPlanning")
|
2021-05-25 19:01:20 +00:00
|
|
|
|
|
|
|
|
2021-06-01 12:15:51 +00:00
|
|
|
def create_app(config):
|
2021-05-26 11:55:22 +00:00
|
|
|
"""Flask app creation"""
|
|
|
|
app = Flask(__name__, static_folder="static", template_folder="view")
|
2021-06-01 12:15:51 +00:00
|
|
|
if not config:
|
|
|
|
config = IniConfig()
|
2021-05-26 11:55:22 +00:00
|
|
|
app.config.from_object(config)
|
|
|
|
|
|
|
|
# set logger
|
|
|
|
logfile = app.config["LOG"]["log_file"]
|
|
|
|
if logfile:
|
|
|
|
handler = TimedRotatingFileHandler(logfile, when="midnight")
|
|
|
|
handler.setFormatter(
|
|
|
|
logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
|
|
|
|
)
|
|
|
|
logger.addHandler(handler)
|
|
|
|
loglevel = app.config["LOG"]["log_level"]
|
|
|
|
if loglevel:
|
|
|
|
logger.setLevel(getattr(logging, loglevel.upper(), logging.NOTSET))
|
2021-05-25 19:01:20 +00:00
|
|
|
|
|
|
|
# Initialize database
|
|
|
|
init_database(app.config["BASE"]["database_uri"])
|
|
|
|
Pony(app)
|
2021-05-26 11:56:20 +00:00
|
|
|
|
|
|
|
# create flask blueprint
|
|
|
|
app.register_blueprint(api, url_prefix="/api/v1")
|
|
|
|
app.register_blueprint(frontend)
|
|
|
|
|
2021-05-25 19:01:20 +00:00
|
|
|
return app
|