Browse Source

Move tween config into tween module

merge-requests/85/head
Deimos 5 years ago
parent
commit
42277048bc
  1. 5
      tildes/tildes/__init__.py
  2. 8
      tildes/tildes/tweens.py

5
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.jinja")
config.include("tildes.json") config.include("tildes.json")
config.include("tildes.routes") config.include("tildes.routes")
config.include("tildes.tweens")
config.add_webasset("javascript", Bundle(output="js/tildes.js")) config.add_webasset("javascript", Bundle(output="js/tildes.js"))
config.add_webasset("javascript-third-party", Bundle(output="js/third_party.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.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_static_view("images", "/images")
config.add_request_method(is_safe_request_method, "is_safe_method", reify=True) config.add_request_method(is_safe_request_method, "is_safe_method", reify=True)

8
tildes/tildes/tweens.py

@ -7,6 +7,7 @@ from time import time
from typing import Callable from typing import Callable
from prometheus_client import Histogram from prometheus_client import Histogram
from pyramid.config import Configurator
from pyramid.registry import Registry from pyramid.registry import Registry
from pyramid.request import Request from pyramid.request import Request
from pyramid.response import Response from pyramid.response import Response
@ -115,3 +116,10 @@ def theme_cookie_tween_factory(handler: Callable, registry: Registry) -> Callabl
return response return response
return theme_cookie_tween 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")
Loading…
Cancel
Save