This repository has been archived on 2022-02-09. You can view files and clone it, but cannot push or open issues or pull requests.
disclosemypay.org/section7/application.py

34 lines
1.0 KiB
Python

import flask
import flask_assets
from section7 import configuration
from section7 import database
from section7 import filters
from section7 import router
class Section7Flask(flask.Flask):
"""Stub class to typehint the ``section7`` attribute with the application config"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.section7 = configuration.load()
APPLICATION = Section7Flask(__name__)
assets = flask_assets.Environment(APPLICATION)
# Register the global application handler
APPLICATION.register_error_handler(Exception, router.handle_error)
# Initialize the database connection
APPLICATION.before_first_request(database.initialize)
# Inject the custom jinja2 filters so that they're available in the templates
for custom_filter in filters.FILTERS:
APPLICATION.jinja_env.filters[custom_filter.__name__] = custom_filter
# Attach the application route endpoints
for route in router.ROUTES:
APPLICATION.route(route.route, methods=list(route.methods))(route.entrypoint)