Skip to content

Commit

Permalink
Simplify method_router types
Browse files Browse the repository at this point in the history
  • Loading branch information
Orhan Hirsch committed Jan 11, 2023
1 parent 4682518 commit 885f8c1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions django_api_decorator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

def method_router(
csrf_exempt: bool | None = None,
**views: Callable[Concatenate[HttpRequest, P], HttpResponse],
) -> Callable[Concatenate[HttpRequest, P], HttpResponse]:
**views: Callable[..., HttpResponse],
) -> Callable[..., HttpResponse]:
"""
Returns a view that dispatches to different views based on the request method.
This allows us to have plain function views for each HTTP method, rather than
Expand Down Expand Up @@ -57,4 +57,4 @@ def call_view(

call_view._method_router_views = views # type: ignore[attr-defined]

return cast(Callable[Concatenate[HttpRequest, P], HttpResponse], call_view)
return cast(Callable[..., HttpResponse], call_view)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-api-decorator"
version = "0.1.3"
version = "0.1.4"
description = "A collection of tools to build function based Django APIs"
authors = ["Oda <[email protected]>"]
license = "MIT"
Expand Down
6 changes: 5 additions & 1 deletion tests/test_method_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.test.client import Client
from django.test.utils import override_settings
from django.urls import path
from pydantic import BaseModel

from django_api_decorator.decorators import api
from django_api_decorator.utils import method_router
Expand All @@ -17,8 +18,11 @@ def test_allowed_methods(client: Client) -> None:
def get_view(request: HttpRequest) -> JsonResponse:
return JsonResponse({"data": True})

class Body(BaseModel):
name: str

@api(method="POST", login_required=False)
def post_view(request: HttpRequest) -> JsonResponse:
def post_view(request: HttpRequest, body: Body) -> JsonResponse:
return JsonResponse({"data": True})

urls = [
Expand Down

0 comments on commit 885f8c1

Please sign in to comment.