""" Superx Budget GUI """ from pathlib import Path from pyramid.view import notfound_view_config from pyramid.config import Configurator from pyramid.session import JSONSerializer, SignedCookieSessionFactory from pyramid.httpexceptions import HTTPFound from ..overview import create_overview # noqa: F401 from ..exceptions import BudgetParserError, SuperXParserError # noqa: F401 XLSX_CONTENT_TYPE = "application/vnd.ms-excel" def root_factory(request): return {} def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ with Configurator(settings=settings) as config: config.include("pyramid_jinja2") session_factory = SignedCookieSessionFactory( settings["session.secret"], serializer=JSONSerializer() ) config.set_session_factory(session_factory) config.set_root_factory(root_factory) config.add_request_method( lambda r: Path(settings["budgets.dir"]), "budgets_dir", reify=True, ) age = int(settings.get("static_views.cache_max_age", 0)) config.add_static_view("static", "static", cache_max_age=age) config.scan() return config.make_wsgi_app() @notfound_view_config() def not_found(context, request): return HTTPFound("/")