From 42277048bc51c276e05dc5694d9f2da04aae7ad7 Mon Sep 17 00:00:00 2001 From: Deimos Date: Tue, 10 Sep 2019 18:56:40 -0600 Subject: [PATCH] Move tween config into tween module --- tildes/tildes/__init__.py | 5 +---- tildes/tildes/tweens.py | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) 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")