django-small-view-set 0.2.3__tar.gz → 0.2.5__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.
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/PKG-INFO +1 -2
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/pyproject.toml +2 -3
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/small_view_set.py +78 -7
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/LICENSE +0 -0
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/README.md +0 -0
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/README.md +0 -0
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/__init__.py +0 -0
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/config.py +0 -0
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/decorators.py +0 -0
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/exceptions.py +0 -0
- {django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/helpers.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: django-small-view-set
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.5
|
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
|
@@ -14,7 +14,6 @@ Classifier: Programming Language :: Python :: 3.9
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.10
|
15
15
|
Classifier: Programming Language :: Python :: 3.11
|
16
16
|
Requires-Dist: django (>=3.2)
|
17
|
-
Requires-Dist: pytest-django (>=4.11.1,<5.0.0)
|
18
17
|
Project-URL: Repository, https://github.com/nateonguitar/django-small-view-set
|
19
18
|
Description-Content-Type: text/markdown
|
20
19
|
|
@@ -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.
|
7
|
+
version = "0.2.5"
|
8
8
|
description = "A lightweight Django ViewSet alternative with minimal abstraction."
|
9
9
|
readme = "README.md"
|
10
10
|
authors = ["Nate Brooks"]
|
@@ -18,11 +18,10 @@ packages = [
|
|
18
18
|
[tool.poetry.dependencies]
|
19
19
|
python = ">=3.8"
|
20
20
|
django = ">=3.2"
|
21
|
-
pytest-django = "^4.11.1"
|
22
21
|
|
23
22
|
[tool.poetry.dev-dependencies]
|
24
23
|
pytest = "*"
|
25
|
-
pytest-django = "
|
24
|
+
pytest-django = "^4.11.1"
|
26
25
|
|
27
26
|
[tool.pytest.ini_options]
|
28
27
|
DJANGO_SETTINGS_MODULE = "tests.settings"
|
{django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/small_view_set.py
RENAMED
@@ -81,7 +81,83 @@ class SmallViewSet:
|
|
81
81
|
pass
|
82
82
|
|
83
83
|
@endpoint(allowed_methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'])
|
84
|
-
async def
|
84
|
+
async def default_router_async(self, request: Request, pk=None, *args, **kwargs):
|
85
|
+
"""
|
86
|
+
This method routes requests to the appropriate method based on the HTTP method and presence of a primary key (pk).
|
87
|
+
|
88
|
+
It also handles errors and returns appropriate JSON responses by using the decorator @endpoint(allowed_method=[]).
|
89
|
+
|
90
|
+
GET/POST for collection endpoints and GET/PUT/PATCH/DELETE for detail endpoints.
|
91
|
+
|
92
|
+
Example:
|
93
|
+
```
|
94
|
+
# Note: AppViewSet is a subclass of SmallViewSet with overridden protect methods with more specific logic.
|
95
|
+
|
96
|
+
class CommentViewSet(AppViewSet):
|
97
|
+
def urlpatterns(self):
|
98
|
+
return [
|
99
|
+
path('api/comments/', self.default_router_async, name='comments_collection'),
|
100
|
+
path('api/comments/<int:pk>/', self.default_router_async, name='comments_detail'),
|
101
|
+
path('api/comments/<int:pk>/custom_put/', self.custom_put, name='comments_custom_put_detail'),
|
102
|
+
]
|
103
|
+
|
104
|
+
@endpoint(allowed_method=['POST'])
|
105
|
+
def create(self, request: Request):
|
106
|
+
self.protect_create(request)
|
107
|
+
. . .
|
108
|
+
|
109
|
+
@endpoint(allowed_method=['PUT', 'PATCH'])
|
110
|
+
def update(self, request: Request, pk: int):
|
111
|
+
self.protect_update(request)
|
112
|
+
. . .
|
113
|
+
|
114
|
+
@endpoint(allowed_method=['PUT'])
|
115
|
+
def custom_put(self, request: Request, pk: int):
|
116
|
+
self.protect_update(request)
|
117
|
+
. . .
|
118
|
+
|
119
|
+
@endpoint(allowed_method=['GET'])
|
120
|
+
@disable_endpoint
|
121
|
+
def some_disabled_endpoint(self, request: Request):
|
122
|
+
self.protect_retrieve(request)
|
123
|
+
. . .
|
124
|
+
```
|
125
|
+
"""
|
126
|
+
func = None
|
127
|
+
if pk is None:
|
128
|
+
if request.method == 'GET':
|
129
|
+
if hasattr(self, 'list'):
|
130
|
+
func = self.list
|
131
|
+
|
132
|
+
elif request.method == 'POST':
|
133
|
+
if hasattr(self, 'create'):
|
134
|
+
func = self.create
|
135
|
+
else:
|
136
|
+
if request.method == 'GET':
|
137
|
+
if hasattr(self, 'retrieve'):
|
138
|
+
func = self.retrieve
|
139
|
+
|
140
|
+
elif request.method == 'PUT':
|
141
|
+
if hasattr(self, 'put'):
|
142
|
+
func = self.put
|
143
|
+
|
144
|
+
elif request.method == 'PATCH':
|
145
|
+
if hasattr(self, 'patch'):
|
146
|
+
func = self.patch
|
147
|
+
|
148
|
+
elif request.method == 'DELETE':
|
149
|
+
if hasattr(self, 'delete'):
|
150
|
+
func = self.delete
|
151
|
+
|
152
|
+
if func is None:
|
153
|
+
raise MethodNotAllowed(request.method)
|
154
|
+
if pk is not None:
|
155
|
+
kwargs['pk'] = pk
|
156
|
+
return await func(request, *args, **kwargs)
|
157
|
+
|
158
|
+
|
159
|
+
@endpoint(allowed_methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'])
|
160
|
+
def default_router(self, request: Request, pk=None, *args, **kwargs):
|
85
161
|
"""
|
86
162
|
This method routes requests to the appropriate method based on the HTTP method and presence of a primary key (pk).
|
87
163
|
|
@@ -151,11 +227,6 @@ class SmallViewSet:
|
|
151
227
|
|
152
228
|
if func is None:
|
153
229
|
raise MethodNotAllowed(request.method)
|
154
|
-
|
155
230
|
if pk is not None:
|
156
231
|
kwargs['pk'] = pk
|
157
|
-
|
158
|
-
if inspect.iscoroutinefunction(func):
|
159
|
-
return await func(request, *args, **kwargs)
|
160
|
-
else:
|
161
|
-
return func(request, *args, **kwargs)
|
232
|
+
return func(request, *args, **kwargs)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/decorators.py
RENAMED
File without changes
|
{django_small_view_set-0.2.3 → django_small_view_set-0.2.5}/src/small_view_set/exceptions.py
RENAMED
File without changes
|
File without changes
|