itplanning/ITPlanning/app.py

36 lines
1.1 KiB
Python
Raw Normal View History

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
#from ITPlanning.frontend import frontend
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
logger = logging.getLogger("ITPlanning")
2021-05-25 19:01:20 +00:00
def create_app():
2021-05-26 11:55:22 +00:00
"""Flask app creation"""
app = Flask(__name__, static_folder="static", template_folder="view")
config = IniConfig()
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
logger.warning(app.config["BASE"]["database_uri"])
init_database(app.config["BASE"]["database_uri"])
Pony(app)
return app