59 lines
1.2 KiB
Python
Executable File
59 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python
|
|
"""Application Flask: AutoSco"""
|
|
|
|
import datetime
|
|
from pprint import pprint as pp
|
|
|
|
import click
|
|
import flask
|
|
from flask.cli import with_appcontext
|
|
from flask.templating import render_template
|
|
|
|
import app as mapp
|
|
from app import create_app, cli
|
|
from app.utils import utils as scu
|
|
|
|
from config import RunningConfig
|
|
from scodoc import api
|
|
|
|
app = create_app(RunningConfig)
|
|
cli.register(app)
|
|
|
|
|
|
@app.context_processor
|
|
def inject_utils():
|
|
"Make scu available in all Jinja templates"
|
|
# if modified, put the same in conftest.py#27
|
|
return {
|
|
"cfg": RunningConfig,
|
|
"DEBUG": flask.current_app.config["DEBUG"],
|
|
"scu": scu,
|
|
}
|
|
|
|
|
|
@app.shell_context_processor
|
|
def make_shell_context():
|
|
import app as mapp # le package app
|
|
|
|
return {
|
|
"api": api,
|
|
"ctx": app.test_request_context(),
|
|
"current_app": flask.current_app,
|
|
"flask": flask,
|
|
"mapp": mapp,
|
|
"pp": pp,
|
|
}
|
|
|
|
|
|
@app.template_filter()
|
|
def format_date(value:str|datetime.datetime):
|
|
"""Format a date dd/mm/yyyy"""
|
|
if isinstance(value, str):
|
|
value = datetime.datetime.fromisoformat(value)
|
|
return value.strftime("%d/%m/%Y")
|
|
|
|
|
|
# Start using:
|
|
# flask run -p 5001 --host 0.0.0.0 --debug
|
|
|