django-small-view-set 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django-small-view-set
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A lightweight Django ViewSet alternative with minimal abstraction.
5
5
  Home-page: https://github.com/nateonguitar/django-small-view-set
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "django-small-view-set"
7
- version = "0.2.2"
7
+ version = "0.2.3"
8
8
  description = "A lightweight Django ViewSet alternative with minimal abstraction."
9
9
  readme = "README.md"
10
10
  authors = ["Nate Brooks"]
@@ -61,7 +61,7 @@ def endpoint_disabled(func):
61
61
  ```python
62
62
  class ExampleViewSet(SmallViewSet):
63
63
 
64
- @default_handle_endpoint_exceptions
64
+ @endpoint(allowed_method=['GET'])
65
65
  @endpoint_disabled
66
66
  def retrieve(self, request: Request) -> JsonResponse:
67
67
  self.protect_retrieve(request)
@@ -1,9 +1,10 @@
1
1
  import inspect
2
2
  import json
3
3
  import logging
4
- from django.http import JsonResponse
5
4
  from urllib.request import Request
6
5
 
6
+
7
+ from .decorators import endpoint
7
8
  from .exceptions import BadRequest, MethodNotAllowed
8
9
 
9
10
  logger = logging.getLogger('app')
@@ -79,11 +80,12 @@ class SmallViewSet:
79
80
  """
80
81
  pass
81
82
 
83
+ @endpoint(allowed_methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'])
82
84
  async def default_router(self, request: Request, pk=None, *args, **kwargs):
83
85
  """
84
86
  This method routes requests to the appropriate method based on the HTTP method and presence of a primary key (pk).
85
87
 
86
- It also handles errors and returns appropriate JSON responses by using the decorator @default_handle_endpoint_exceptions.
88
+ It also handles errors and returns appropriate JSON responses by using the decorator @endpoint(allowed_method=[]).
87
89
 
88
90
  GET/POST for collection endpoints and GET/PUT/PATCH/DELETE for detail endpoints.
89
91
 
@@ -99,23 +101,23 @@ class SmallViewSet:
99
101
  path('api/comments/<int:pk>/custom_put/', self.custom_put, name='comments_custom_put_detail'),
100
102
  ]
101
103
 
102
- @default_handle_endpoint_exceptions
104
+ @endpoint(allowed_method=['POST'])
103
105
  def create(self, request: Request):
104
106
  self.protect_create(request)
105
107
  . . .
106
108
 
107
- @default_handle_endpoint_exceptions
109
+ @endpoint(allowed_method=['PUT', 'PATCH'])
108
110
  def update(self, request: Request, pk: int):
109
111
  self.protect_update(request)
110
112
  . . .
111
113
 
112
- @default_handle_endpoint_exceptions
114
+ @endpoint(allowed_method=['PUT'])
113
115
  def custom_put(self, request: Request, pk: int):
114
116
  self.protect_update(request)
115
117
  . . .
116
118
 
117
119
  @disable_endpoint
118
- @default_handle_endpoint_exceptions
120
+ @endpoint(allowed_method=['GET'])
119
121
  def some_disabled_endpoint(self, request: Request):
120
122
  self.protect_retrieve(request)
121
123
  . . .