diff --git a/tildes/tildes/__init__.py b/tildes/tildes/__init__.py index 8528847..fa0f314 100644 --- a/tildes/tildes/__init__.py +++ b/tildes/tildes/__init__.py @@ -32,6 +32,7 @@ def main(global_config: Dict[str, str], **settings: str) -> PrefixMiddleware: config.include("tildes.jinja") config.include("tildes.json") config.include("tildes.routes") + config.include("tildes.tweens") config.add_webasset("javascript", Bundle(output="js/tildes.js")) config.add_webasset("javascript-third-party", Bundle(output="js/third_party.js")) @@ -39,10 +40,6 @@ def main(global_config: Dict[str, str], **settings: str) -> PrefixMiddleware: config.scan("tildes.views") - config.add_tween("tildes.tweens.http_method_tween_factory") - config.add_tween("tildes.tweens.metrics_tween_factory") - config.add_tween("tildes.tweens.theme_cookie_tween_factory") - config.add_static_view("images", "/images") config.add_request_method(is_safe_request_method, "is_safe_method", reify=True) diff --git a/tildes/tildes/tweens.py b/tildes/tildes/tweens.py index 00d44ca..8c5a385 100644 --- a/tildes/tildes/tweens.py +++ b/tildes/tildes/tweens.py @@ -7,6 +7,7 @@ from time import time from typing import Callable from prometheus_client import Histogram +from pyramid.config import Configurator from pyramid.registry import Registry from pyramid.request import Request from pyramid.response import Response @@ -115,3 +116,10 @@ def theme_cookie_tween_factory(handler: Callable, registry: Registry) -> Callabl return response return theme_cookie_tween + + +def includeme(config: Configurator) -> None: + """Attach Tildes tweens to the Pyramid config.""" + config.add_tween("tildes.tweens.http_method_tween_factory") + config.add_tween("tildes.tweens.metrics_tween_factory") + config.add_tween("tildes.tweens.theme_cookie_tween_factory")