django-ninja-aio-crud 0.8.0__py3-none-any.whl → 0.8.2__py3-none-any.whl
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_ninja_aio_crud-0.8.0.dist-info → django_ninja_aio_crud-0.8.2.dist-info}/METADATA +4 -3
- django_ninja_aio_crud-0.8.2.dist-info/RECORD +14 -0
- ninja_aio/__init__.py +1 -1
- ninja_aio/models.py +2 -2
- ninja_aio/renders.py +11 -3
- ninja_aio/views.py +29 -10
- django_ninja_aio_crud-0.8.0.dist-info/RECORD +0 -14
- {django_ninja_aio_crud-0.8.0.dist-info → django_ninja_aio_crud-0.8.2.dist-info}/WHEEL +0 -0
- {django_ninja_aio_crud-0.8.0.dist-info → django_ninja_aio_crud-0.8.2.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: django-ninja-aio-crud
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.2
|
|
4
4
|
Summary: Django Ninja AIO CRUD - Rest Framework
|
|
5
5
|
Author: Giuseppe Casillo
|
|
6
6
|
Requires-Python: >=3.10
|
|
@@ -138,7 +138,7 @@ class Foo(ModelSerializer):
|
|
|
138
138
|
|
|
139
139
|
- post create method is a custom method that comes out to handle actions which will be excuted after that the object is created. It can be used, indeed, for example to handle custom fields' actions.
|
|
140
140
|
|
|
141
|
-
- You can also define optional fields for you Create and Update serializers
|
|
141
|
+
- You can also define optional fields for you Create and Update serializers. To declare an optional fields you have to give the field type too.
|
|
142
142
|
```python
|
|
143
143
|
# models.py
|
|
144
144
|
from django.db import models
|
|
@@ -213,12 +213,13 @@ class Foo(ModelSerializer):
|
|
|
213
213
|
excludes = ["id", "name"]
|
|
214
214
|
optionals = [("bar", str), ("active", bool)]
|
|
215
215
|
```
|
|
216
|
-
- ModelSerializer comes out also with methods executed on object save, them are:
|
|
216
|
+
- ModelSerializer comes out also with methods executed on object save and delete, them are:
|
|
217
217
|
|
|
218
218
|
1. on_create_before_save: code executed on object creation but before saving;
|
|
219
219
|
1. on_create_after_save: code executed on object creation but after saving;
|
|
220
220
|
1. before_save: code executed on every save but before saving;
|
|
221
221
|
1. after_save: code executed on every save but after saving;
|
|
222
|
+
1. on_delete: code executed after object delete;
|
|
222
223
|
|
|
223
224
|
|
|
224
225
|
### APIViewSet
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
ninja_aio/__init__.py,sha256=bsPt3RS3lSEkh5vACssADsknEA5mywwrp1XQlhqXfYs,119
|
|
2
|
+
ninja_aio/api.py,sha256=Fe6l3YCy7MW5TY4-Lbl80CFuK2NT2Y7tHfmqPk6Mqak,1735
|
|
3
|
+
ninja_aio/auth.py,sha256=fKboioU4sezPukKJukIwiboxml_KV7irhCH3vGYt5pU,1008
|
|
4
|
+
ninja_aio/exceptions.py,sha256=gPnZX1Do2GXudbU8wDYkwhO70Qj0ZNrIJJ2UXRs9vYk,2241
|
|
5
|
+
ninja_aio/models.py,sha256=Kw9PCg4vgo1Y33XCxmwUGg9V1-0wkVxFByHdbDt5P78,18588
|
|
6
|
+
ninja_aio/parsers.py,sha256=e_4lGCPV7zs-HTqtdJTc8yQD2KPAn9njbL8nF_Mmgkc,153
|
|
7
|
+
ninja_aio/renders.py,sha256=0eYklRKd59aV4cZDom5vLZyA99Ob17OwkpMybsRXvyg,1970
|
|
8
|
+
ninja_aio/schemas.py,sha256=EgRkfhnzZqwGvdBmqlZixMtMcoD1ZxV_qzJ3fmaAy20,113
|
|
9
|
+
ninja_aio/types.py,sha256=TJSGlA7bt4g9fvPhJ7gzH5tKbLagPmZUzfgttEOp4xs,468
|
|
10
|
+
ninja_aio/views.py,sha256=N7SCBdFCub73MzofutZ0N7E_gXa3-CQvLwHGrf0eKHw,10106
|
|
11
|
+
django_ninja_aio_crud-0.8.2.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
|
|
12
|
+
django_ninja_aio_crud-0.8.2.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
13
|
+
django_ninja_aio_crud-0.8.2.dist-info/METADATA,sha256=IjqhzpqxoFjfCqiJ-0rLKHmgXcAF3gYgu_VIosBLexM,14138
|
|
14
|
+
django_ninja_aio_crud-0.8.2.dist-info/RECORD,,
|
ninja_aio/__init__.py
CHANGED
ninja_aio/models.py
CHANGED
|
@@ -95,7 +95,7 @@ class ModelUtil:
|
|
|
95
95
|
return reverse_rels
|
|
96
96
|
|
|
97
97
|
async def parse_input_data(self, request: HttpRequest, data: Schema):
|
|
98
|
-
payload = data.model_dump()
|
|
98
|
+
payload = data.model_dump(mode="json")
|
|
99
99
|
customs = {}
|
|
100
100
|
optionals = []
|
|
101
101
|
if isinstance(self.model, ModelSerializerMeta):
|
|
@@ -128,7 +128,7 @@ class ModelUtil:
|
|
|
128
128
|
|
|
129
129
|
async def parse_output_data(self, request: HttpRequest, data: Schema):
|
|
130
130
|
olds_k: list[dict] = []
|
|
131
|
-
payload = data.model_dump()
|
|
131
|
+
payload = data.model_dump(mode="json")
|
|
132
132
|
for k, v in payload.items():
|
|
133
133
|
try:
|
|
134
134
|
field_obj = (await agetattr(self.model, k)).field
|
ninja_aio/renders.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import base64
|
|
2
|
+
from ipaddress import IPv4Address, IPv6Address
|
|
2
3
|
|
|
3
4
|
import orjson
|
|
4
5
|
from django.http import HttpRequest
|
|
@@ -31,16 +32,23 @@ class ORJSONRenderer(BaseRenderer):
|
|
|
31
32
|
for k, v in data.items():
|
|
32
33
|
if isinstance(v, bytes):
|
|
33
34
|
data |= {k: base64.b64encode(v).decode()}
|
|
35
|
+
continue
|
|
36
|
+
if isinstance(v, (IPv4Address, IPv6Address)):
|
|
37
|
+
data |= {k: str(v)}
|
|
38
|
+
continue
|
|
34
39
|
if isinstance(v, dict):
|
|
35
40
|
for k_rel, v_rel in v.items():
|
|
36
|
-
if
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
if isinstance(v_rel, bytes):
|
|
42
|
+
v |= {k_rel: base64.b64encode(v_rel).decode()}
|
|
43
|
+
if isinstance(v_rel, (IPv4Address, IPv6Address)):
|
|
44
|
+
v |= {k_rel: str(v_rel)}
|
|
39
45
|
data |= {k: v}
|
|
40
46
|
if isinstance(v, list):
|
|
41
47
|
for index_rel, f_rel in enumerate(v):
|
|
42
48
|
for k_rel, v_rel in f_rel.items():
|
|
43
49
|
if isinstance(v_rel, bytes):
|
|
44
50
|
v[index_rel] |= {k_rel: base64.b64encode(v_rel).decode()}
|
|
51
|
+
if isinstance(v_rel, (IPv4Address, IPv6Address)):
|
|
52
|
+
v[index_rel] |= {k_rel: str(v_rel)}
|
|
45
53
|
data |= {k: v}
|
|
46
54
|
return data
|
ninja_aio/views.py
CHANGED
|
@@ -72,6 +72,10 @@ class APIViewSet:
|
|
|
72
72
|
schema_out: Schema | None = None
|
|
73
73
|
schema_update: Schema | None = None
|
|
74
74
|
auth: list | None = NOT_SET
|
|
75
|
+
get_auth: list | None = NOT_SET
|
|
76
|
+
post_auth: list | None = NOT_SET
|
|
77
|
+
patch_auth: list | None = NOT_SET
|
|
78
|
+
delete_auth: list | None = NOT_SET
|
|
75
79
|
pagination_class: type[AsyncPaginationBase] = PageNumberPagination
|
|
76
80
|
query_params: dict[str, tuple[type, ...]] = {}
|
|
77
81
|
disable: list[type[VIEW_TYPES]] = []
|
|
@@ -105,6 +109,21 @@ class APIViewSet:
|
|
|
105
109
|
"delete": (None, self.delete_view),
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
def _auth_view(self, view_type: str):
|
|
113
|
+
return getattr(self, f"{view_type}_auth") if self.auth is not NOT_SET else self.auth
|
|
114
|
+
|
|
115
|
+
def get_view_auth(self):
|
|
116
|
+
return self._auth_view("get")
|
|
117
|
+
|
|
118
|
+
def post_view_auth(self):
|
|
119
|
+
return self._auth_view("post")
|
|
120
|
+
|
|
121
|
+
def patch_view_auth(self):
|
|
122
|
+
return self._auth_view("patch")
|
|
123
|
+
|
|
124
|
+
def delete_view_auth(self):
|
|
125
|
+
return self._auth_view("delete")
|
|
126
|
+
|
|
108
127
|
def _generate_schema(self, fields: dict, name: str) -> Schema:
|
|
109
128
|
return create_model(f"{self.model_util.model_name}{name}", **fields)
|
|
110
129
|
|
|
@@ -141,10 +160,10 @@ class APIViewSet:
|
|
|
141
160
|
def create_view(self):
|
|
142
161
|
@self.router.post(
|
|
143
162
|
self.path,
|
|
144
|
-
auth=self.
|
|
163
|
+
auth=self.post_view_auth(),
|
|
145
164
|
response={201: self.schema_out, self.error_codes: GenericMessageSchema},
|
|
146
165
|
)
|
|
147
|
-
async def create(request: HttpRequest, data: self.schema_in):
|
|
166
|
+
async def create(request: HttpRequest, data: self.schema_in): # type: ignore
|
|
148
167
|
return 201, await self.model_util.create_s(request, data, self.schema_out)
|
|
149
168
|
|
|
150
169
|
create.__name__ = f"create_{self.model_util.model_name}"
|
|
@@ -153,7 +172,7 @@ class APIViewSet:
|
|
|
153
172
|
def list_view(self):
|
|
154
173
|
@self.router.get(
|
|
155
174
|
self.path,
|
|
156
|
-
auth=self.
|
|
175
|
+
auth=self.get_view_auth(),
|
|
157
176
|
response={
|
|
158
177
|
200: List[self.schema_out],
|
|
159
178
|
self.error_codes: GenericMessageSchema,
|
|
@@ -161,7 +180,7 @@ class APIViewSet:
|
|
|
161
180
|
)
|
|
162
181
|
@paginate(self.pagination_class)
|
|
163
182
|
async def list(
|
|
164
|
-
request: HttpRequest, filters: Query[self.filters_schema] = None
|
|
183
|
+
request: HttpRequest, filters: Query[self.filters_schema] = None # type: ignore
|
|
165
184
|
):
|
|
166
185
|
qs = self.model.objects.select_related()
|
|
167
186
|
if isinstance(self.model, ModelSerializerMeta):
|
|
@@ -183,10 +202,10 @@ class APIViewSet:
|
|
|
183
202
|
def retrieve_view(self):
|
|
184
203
|
@self.router.get(
|
|
185
204
|
self.path_retrieve,
|
|
186
|
-
auth=self.
|
|
205
|
+
auth=self.get_view_auth(),
|
|
187
206
|
response={200: self.schema_out, self.error_codes: GenericMessageSchema},
|
|
188
207
|
)
|
|
189
|
-
async def retrieve(request: HttpRequest, pk: Path[self.path_schema]):
|
|
208
|
+
async def retrieve(request: HttpRequest, pk: Path[self.path_schema]): # type: ignore
|
|
190
209
|
obj = await self.model_util.get_object(request, self._get_pk(pk))
|
|
191
210
|
return await self.model_util.read_s(request, obj, self.schema_out)
|
|
192
211
|
|
|
@@ -196,11 +215,11 @@ class APIViewSet:
|
|
|
196
215
|
def update_view(self):
|
|
197
216
|
@self.router.patch(
|
|
198
217
|
self.path_retrieve,
|
|
199
|
-
auth=self.
|
|
218
|
+
auth=self.patch_view_auth(),
|
|
200
219
|
response={200: self.schema_out, self.error_codes: GenericMessageSchema},
|
|
201
220
|
)
|
|
202
221
|
async def update(
|
|
203
|
-
request: HttpRequest, data: self.schema_update, pk: Path[self.path_schema]
|
|
222
|
+
request: HttpRequest, data: self.schema_update, pk: Path[self.path_schema] # type: ignore
|
|
204
223
|
):
|
|
205
224
|
return await self.model_util.update_s(
|
|
206
225
|
request, data, self._get_pk(pk), self.schema_out
|
|
@@ -212,10 +231,10 @@ class APIViewSet:
|
|
|
212
231
|
def delete_view(self):
|
|
213
232
|
@self.router.delete(
|
|
214
233
|
self.path_retrieve,
|
|
215
|
-
auth=self.
|
|
234
|
+
auth=self.delete_view_auth(),
|
|
216
235
|
response={204: None, self.error_codes: GenericMessageSchema},
|
|
217
236
|
)
|
|
218
|
-
async def delete(request: HttpRequest, pk: Path[self.path_schema]):
|
|
237
|
+
async def delete(request: HttpRequest, pk: Path[self.path_schema]): # type: ignore
|
|
219
238
|
return 204, await self.model_util.delete_s(request, self._get_pk(pk))
|
|
220
239
|
|
|
221
240
|
delete.__name__ = f"delete_{self.model_util.model_name}"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
ninja_aio/__init__.py,sha256=4Y_TTHJMyRwXROgTk4ceYBEInHJp915fVqn25INc0mw,119
|
|
2
|
-
ninja_aio/api.py,sha256=Fe6l3YCy7MW5TY4-Lbl80CFuK2NT2Y7tHfmqPk6Mqak,1735
|
|
3
|
-
ninja_aio/auth.py,sha256=fKboioU4sezPukKJukIwiboxml_KV7irhCH3vGYt5pU,1008
|
|
4
|
-
ninja_aio/exceptions.py,sha256=gPnZX1Do2GXudbU8wDYkwhO70Qj0ZNrIJJ2UXRs9vYk,2241
|
|
5
|
-
ninja_aio/models.py,sha256=eliA49Bvga9hLgjOIzTg4WTxZ8usBy74LyUcp5Njh7c,18566
|
|
6
|
-
ninja_aio/parsers.py,sha256=e_4lGCPV7zs-HTqtdJTc8yQD2KPAn9njbL8nF_Mmgkc,153
|
|
7
|
-
ninja_aio/renders.py,sha256=mHeKNJtmDhZmgFpS9B6SPn5uZFcyVXrsoMhr149LeW8,1555
|
|
8
|
-
ninja_aio/schemas.py,sha256=EgRkfhnzZqwGvdBmqlZixMtMcoD1ZxV_qzJ3fmaAy20,113
|
|
9
|
-
ninja_aio/types.py,sha256=TJSGlA7bt4g9fvPhJ7gzH5tKbLagPmZUzfgttEOp4xs,468
|
|
10
|
-
ninja_aio/views.py,sha256=sMxIymLQ6dpeuf4-akYI1PrNzpfJf0S0iS2cC8BnHXM,9387
|
|
11
|
-
django_ninja_aio_crud-0.8.0.dist-info/licenses/LICENSE,sha256=yrDAYcm0gRp_Qyzo3GQa4BjYjWRkAhGC8QRva__RYq0,1073
|
|
12
|
-
django_ninja_aio_crud-0.8.0.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
|
|
13
|
-
django_ninja_aio_crud-0.8.0.dist-info/METADATA,sha256=3Bc2ezvyizII3UNfHexWaH-1pp39uRNO87foJDdkCDc,14126
|
|
14
|
-
django_ninja_aio_crud-0.8.0.dist-info/RECORD,,
|
|
File without changes
|
{django_ninja_aio_crud-0.8.0.dist-info → django_ninja_aio_crud-0.8.2.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|