Skip to content

Commit 2550fc3

Browse files
authored
Merge pull request #331 from eadwinCode/reflect_module_controller
refactor: migrate controller metadata to reflect-based storage
2 parents 7ac1e17 + b1d54a1 commit 2550fc3

32 files changed

+1464
-446
lines changed

ninja_extra/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
THROTTLED_OBJECTS = "__throttled_objects__"
1919
ROUTE_FUNCTION = "__route_function__"
2020

21+
CONTROLLER_OPERATION_HANDLER_KEY = "CONTROLLER_OPERATION_HANDLER"
22+
CONTROLLER_WATERMARK = "CONTROLLER_WATERMARK"
23+
ROUTE_OBJECT = "ROUTE_OBJECT"
24+
ROUTE_OBJECT_FUNCTION = "ROUTE_OBJECT_FUNCTION"
25+
OPERATION_ENDPOINT_KEY = "OPERATION_ENDPOINT_KEY"
26+
API_CONTROLLER_INSTANCE = "API_CONTROLLER_INSTANCE"
27+
ORDERATOR_OBJECT = "ORDERATOR_WATERMARK"
28+
SEARCH_OPERATOR_OBJECT = "SEARCH_OPERATOR_OBJECT"
29+
PAGINATOR_OBJECT = "PAGINATOR_WATERMARK"
30+
NINJA_EXTRA_API_CONTROLLER_REGISTERED_KEY = "NINJA_EXTRA_API_CONTROLLER_REGISTERED_KEY"
31+
2132
ROUTE_CONTEXT_VAR: contextvars.ContextVar[t.Optional["RouteContext"]] = (
2233
contextvars.ContextVar("ROUTE_CONTEXT_VAR")
2334
)

ninja_extra/context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def __init__(
5858
self._view_signature = view_signature
5959
self._has_computed_route_parameters = False
6060

61+
@property
62+
def api(self) -> "NinjaExtraAPI":
63+
assert self._api, "API instance is not set in RouteContext"
64+
return self._api
65+
6166
@property
6267
def has_computed_route_parameters(self) -> bool:
6368
return self._has_computed_route_parameters

ninja_extra/controllers/__init__.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import typing as t
2-
import warnings
3-
41
from .base import ControllerBase, ModelControllerBase, api_controller
52
from .model import (
63
ModelAsyncEndpointFactory,
@@ -49,16 +46,3 @@
4946
"ModelEndpointFactory",
5047
"ModelAsyncEndpointFactory",
5148
]
52-
53-
54-
def __getattr__(name: str) -> t.Any:
55-
if name == "RouteContext":
56-
warnings.warn(
57-
"RouteContext is deprecated and will be removed in a future version.",
58-
DeprecationWarning,
59-
stacklevel=2,
60-
)
61-
from ninja_extra.context import RouteContext
62-
63-
return RouteContext
64-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)