You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
"""Superx Budget GUI""" |
|
|
|
from pathlib import Path |
|
|
|
from pyramid.authorization import Allow, Authenticated, Everyone |
|
from pyramid.config import Configurator |
|
from pyramid.httpexceptions import HTTPFound |
|
from pyramid.session import JSONSerializer, SignedCookieSessionFactory |
|
from pyramid.view import notfound_view_config |
|
|
|
from ..exceptions import BudgetParserError, SuperXParserError # noqa: F401 |
|
from ..overview import create_overview # noqa: F401 |
|
|
|
XLSX_CONTENT_TYPE = "application/octet-stream" |
|
|
|
|
|
class Root: |
|
__acl__ = [(Allow, Everyone, "login"), (Allow, Authenticated, "view")] # noqa: RUF012 |
|
|
|
def __init__(self, request): |
|
pass |
|
|
|
|
|
def main(global_config, **settings): # noqa: ARG001 |
|
"""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( # noqa: ARG005 |
|
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): # noqa: ARG001 |
|
return HTTPFound("/")
|
|
|