""" 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.security import Allow, Everyone, Authenticated from pyramid.httpexceptions import HTTPFound from ..overview import create_overview # noqa: F401 from ..exceptions import BudgetParserError, SuperXParserError # noqa: F401 XLSX_CONTENT_TYPE = "application/octet-stream" class Root: __acl__ = [(Allow, Everyone, "login"), (Allow, Authenticated, "view")] def __init__(self, request): pass def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ with Configurator(settings=settings) as config: session_factory = SignedCookieSessionFactory( settings["session.secret"], serializer=JSONSerializer() ) config.set_session_factory(session_factory) config.set_root_factory(Root) 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.include("pyramid_jinja2") config.include(".security") config.scan() return config.make_wsgi_app() @notfound_view_config() def not_found(context, request): return HTTPFound("/")