Skip to content

Commit 55ed642

Browse files
authored
Merge pull request #120 from eadwinCode/route_execution_fix
Context Parameter Renamed
2 parents 693dc9d + 2c43904 commit 55ed642

File tree

12 files changed

+51
-44
lines changed

12 files changed

+51
-44
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install Flit
1818
run: pip install flit
1919
- name: Install Dependencies
20-
run: flit install --symlink
20+
run: make install
2121
- name: Install build dependencies
2222
run: pip install build
2323
- name: Build distribution

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Install Flit
1919
run: pip install flit
2020
- name: Install Dependencies
21-
run: flit install --symlink
21+
run: make install
2222
- name: Test
2323
run: pytest --cov=ninja_extra --cov-report=xml tests
2424
- name: Coverage

.github/workflows/test_full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Install Flit
4747
run: pip install flit
4848
- name: Install Dependencies
49-
run: flit install --symlink
49+
run: make install
5050
- name: Ruff Linting Check
5151
run: ruff check ninja_extra tests
5252
- name: mypy

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ clean: ## Removing cached python compiled files
1212
find . -name .ruff_cache | xargs rm -rfv
1313

1414
install:clean ## Install dependencies
15-
flit install --deps develop --symlink
15+
pip install -r requirements.txt
16+
flit install --symlink
17+
18+
install-full: ## Install dependencies
19+
make install
1620
pre-commit install -f
1721

1822
lint:fmt ## Run code linters

docs/contribution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Please take a moment to review the following guidelines before getting started.
2828
4. **Install Dependencies:** Install development libraries and pre-commit hooks.
2929

3030
```bash
31-
make install
31+
make install-full
3232
```
3333

3434
### **Code Style and Formatting**

ninja_extra/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Django Ninja Extra - Class Based Utility and more for Django Ninja(Fast Django REST framework)"""
22

3-
__version__ = "0.20.4"
3+
__version__ = "0.20.5"
44

55
import django
66

ninja_extra/controllers/route/route_functions.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __call__(
5050
*args,
5151
**kwargs,
5252
)
53-
return self.as_view(request, *args, context=context, **kwargs)
53+
return self.as_view(request, *args, route_context=context, **kwargs)
5454

5555
def _get_required_api_func_signature(self) -> Tuple:
5656
skip_parameters = ["self", "request"]
@@ -77,12 +77,14 @@ def _resolve_api_func_signature_(self, context_func: Callable) -> Callable:
7777
def get_view_function(self) -> Callable:
7878
def as_view(
7979
request: HttpRequest,
80-
context: Optional[RouteContext] = None,
80+
route_context: Optional[RouteContext] = None,
8181
*args: Any,
8282
**kwargs: Any,
8383
) -> Any:
84-
context = context or cast(RouteContext, service_resolver(RouteContext))
85-
with self._prep_controller_route_execution(context, **kwargs) as ctx:
84+
_route_context = route_context or cast(
85+
RouteContext, service_resolver(RouteContext)
86+
)
87+
with self._prep_controller_route_execution(_route_context, **kwargs) as ctx:
8688
ctx.controller_instance.check_permissions()
8789
result = self.route.view_func(
8890
ctx.controller_instance, *args, **ctx.view_func_kwargs
@@ -134,14 +136,14 @@ def get_route_execution_context(
134136

135137
@contextmanager
136138
def _prep_controller_route_execution(
137-
self, context: RouteContext, **kwargs: Any
139+
self, route_context: RouteContext, **kwargs: Any
138140
) -> Iterator[RouteFunctionContext]:
139141
controller_instance = self._get_controller_instance()
140-
controller_instance.context = context
142+
controller_instance.context = route_context
141143

142-
api_func_kwargs = dict(**kwargs)
144+
api_func_kwargs = dict(kwargs)
143145
if self.has_request_param:
144-
api_func_kwargs.update(request=context.request)
146+
api_func_kwargs.update(request=route_context.request)
145147
try:
146148
yield RouteFunctionContext(
147149
controller_instance=controller_instance, **api_func_kwargs
@@ -164,14 +166,16 @@ class AsyncRouteFunction(RouteFunction):
164166
def get_view_function(self) -> Callable:
165167
async def as_view(
166168
request: HttpRequest,
167-
context: Optional[RouteContext] = None,
169+
route_context: Optional[RouteContext] = None,
168170
*args: Any,
169171
**kwargs: Any,
170172
) -> Any:
171173
from asgiref.sync import sync_to_async
172174

173-
context = context or cast(RouteContext, service_resolver(RouteContext))
174-
with self._prep_controller_route_execution(context, **kwargs) as ctx:
175+
_route_context = route_context or cast(
176+
RouteContext, service_resolver(RouteContext)
177+
)
178+
with self._prep_controller_route_execution(_route_context, **kwargs) as ctx:
175179
await sync_to_async(ctx.controller_instance.check_permissions)()
176180
result = await self.route.view_func(
177181
ctx.controller_instance, *args, **ctx.view_func_kwargs
@@ -201,4 +205,4 @@ async def __call__(
201205
*args,
202206
**kwargs,
203207
)
204-
return await self.as_view(request, *args, context=context, **kwargs)
208+
return await self.as_view(request, *args, route_context=context, **kwargs)

pyproject.toml

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,30 +53,6 @@ requires-python = ">=3.7"
5353
[tool.flit.metadata.urls]
5454
Documentation = "https://eadwincode.github.io/django-ninja-extra/"
5555

56-
[tool.flit.metadata.requires-extra]
57-
test = [
58-
"pytest",
59-
"pytest-cov",
60-
"pytest-django",
61-
"pytest-asyncio==0.20.3",
62-
"mypy == 1.7.1",
63-
"ruff ==0.1.7",
64-
"ninja-schema>=0.13.4",
65-
"django-stubs",
66-
]
67-
doc = [
68-
"mkdocs >=1.1.2,<2.0.0",
69-
"mkdocs-material >=7.1.9,<8.0.0",
70-
"mdx-include >=1.4.1,<2.0.0",
71-
"mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0",
72-
"markdown-include",
73-
"mkdocstrings"
74-
]
75-
76-
dev = [
77-
"pre-commit"
78-
]
79-
8056
[tool.ruff]
8157
select = [
8258
"E", # pycodestyle errors

requirements-docs.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
markdown-include
2+
mdx-include >=1.4.1,<2.0.0
3+
mkdocs >=1.1.2,<2.0.0
4+
mkdocs-markdownextradata-plugin >=0.1.7,<0.3.0
5+
mkdocs-material >=7.1.9,<8.0.0
6+
mkdocstrings

requirements-tests.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
django-stubs
2+
mypy == 1.7.1
3+
ninja-schema>=0.13.4
4+
pytest
5+
pytest-asyncio==0.20.3
6+
pytest-cov
7+
pytest-django
8+
ruff ==0.1.7

0 commit comments

Comments
 (0)