Move tween config into tween module

This commit is contained in:
Deimos
2019-09-10 18:56:40 -06:00
parent 6f26a94d42
commit 42277048bc
2 changed files with 9 additions and 4 deletions

View File

@@ -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)

View File

@@ -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")