muffin-rest 7.3.3__py3-none-any.whl → 7.3.4__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.
- muffin_rest/peewee/schemas.py +1 -25
- muffin_rest/schemas.py +27 -0
- {muffin_rest-7.3.3.dist-info → muffin_rest-7.3.4.dist-info}/METADATA +1 -1
- {muffin_rest-7.3.3.dist-info → muffin_rest-7.3.4.dist-info}/RECORD +6 -5
- {muffin_rest-7.3.3.dist-info → muffin_rest-7.3.4.dist-info}/LICENSE +0 -0
- {muffin_rest-7.3.3.dist-info → muffin_rest-7.3.4.dist-info}/WHEEL +0 -0
muffin_rest/peewee/schemas.py
CHANGED
|
@@ -2,31 +2,7 @@ import marshmallow as ma
|
|
|
2
2
|
from marshmallow_peewee import DefaultConverter
|
|
3
3
|
from muffin_peewee.fields import IntEnumField, StrEnumField, URLField
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
class EnumField(ma.fields.Field):
|
|
7
|
-
default_error_messages = {
|
|
8
|
-
"unknown": "Must be one of: {choices}.",
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
def __init__(self, enum, **kwargs):
|
|
12
|
-
self.enum = enum
|
|
13
|
-
self.choices_text = ", ".join([str(c.value) for c in enum])
|
|
14
|
-
super().__init__(**kwargs)
|
|
15
|
-
|
|
16
|
-
def _serialize(self, value, attr, obj, **kwargs):
|
|
17
|
-
if value is None:
|
|
18
|
-
return None
|
|
19
|
-
|
|
20
|
-
try:
|
|
21
|
-
return value.value
|
|
22
|
-
except AttributeError:
|
|
23
|
-
raise ma.ValidationError(f"{obj}: {attr} value is invalid: {value}") from None
|
|
24
|
-
|
|
25
|
-
def _deserialize(self, value, attr, data, **kwargs):
|
|
26
|
-
try:
|
|
27
|
-
return self.enum(value)
|
|
28
|
-
except ValueError as error:
|
|
29
|
-
raise self.make_error("unknown", choices=self.choices_text) from error
|
|
5
|
+
from muffin_rest.schemas import EnumField
|
|
30
6
|
|
|
31
7
|
|
|
32
8
|
@DefaultConverter.register(StrEnumField)
|
muffin_rest/schemas.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import marshmallow as ma
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class EnumField(ma.fields.Field):
|
|
5
|
+
default_error_messages = {
|
|
6
|
+
"unknown": "Must be one of: {choices}.",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
def __init__(self, enum, **kwargs):
|
|
10
|
+
self.enum = enum
|
|
11
|
+
self.choices_text = ", ".join([str(c.value) for c in enum])
|
|
12
|
+
super().__init__(**kwargs)
|
|
13
|
+
|
|
14
|
+
def _serialize(self, value, attr, obj, **kwargs):
|
|
15
|
+
if value is None:
|
|
16
|
+
return None
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
return value.value
|
|
20
|
+
except AttributeError:
|
|
21
|
+
raise ma.ValidationError(f"{obj}: {attr} value is invalid: {value}") from None
|
|
22
|
+
|
|
23
|
+
def _deserialize(self, value, attr, data, **kwargs):
|
|
24
|
+
try:
|
|
25
|
+
return self.enum(value)
|
|
26
|
+
except ValueError as error:
|
|
27
|
+
raise self.make_error("unknown", choices=self.choices_text) from error
|
|
@@ -17,12 +17,13 @@ muffin_rest/peewee/filters.py,sha256=ziqpD7uH9vzx_yHKUpOYmduNmM8w-8b7CtRaSoCqECU
|
|
|
17
17
|
muffin_rest/peewee/handler.py,sha256=O84-TmiyNyEhEamTh-DY93ds0hZJzVG8_yekRpF9p3k,5359
|
|
18
18
|
muffin_rest/peewee/openapi.py,sha256=ZZuh7nJVuK9cTJqtOJ_XASe9iJgter-xIjj9YJ8xszI,1111
|
|
19
19
|
muffin_rest/peewee/options.py,sha256=F-UjCbz5rAIXt-D_MtmriiYkOL7wsri6FRt7WCNZzyo,1480
|
|
20
|
-
muffin_rest/peewee/schemas.py,sha256=
|
|
20
|
+
muffin_rest/peewee/schemas.py,sha256=w6jBziUp40mOOjkz_4RCXuY0x5ZDIe9Ob25k1FnZSfc,469
|
|
21
21
|
muffin_rest/peewee/sorting.py,sha256=jLU9d9h8uCV61NbsjkdhDLvh0lCK_6Os-0kIOI-pKwc,1983
|
|
22
22
|
muffin_rest/peewee/types.py,sha256=cgCXhpGHkImKwudA1lulZHz5oJswHH168AiW5MhZRCM,155
|
|
23
23
|
muffin_rest/peewee/utils.py,sha256=wXeneVE1IZl1ROnY28re73H62Y1_tEmoEQYzPhuOyBI,702
|
|
24
24
|
muffin_rest/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
25
|
muffin_rest/redoc.html,sha256=GtuHIMvTuSi8Ro6bgI-G8VB94AljMyfjcZseqtBmGCY,559
|
|
26
|
+
muffin_rest/schemas.py,sha256=FiNUuI7b70zgbg0F0p-CLUSpGmij9uBZDq9fUn9I_q4,814
|
|
26
27
|
muffin_rest/sorting.py,sha256=Z3echqt8ve-p1f7iOVYlFFVsA3ShCXVaXDkVMFTC6tQ,2887
|
|
27
28
|
muffin_rest/sqlalchemy/__init__.py,sha256=WYxb5d4eQqXeT8MwpgdiItAjrOdFm-_5GaG-xtWQ4lk,6362
|
|
28
29
|
muffin_rest/sqlalchemy/filters.py,sha256=bTT7ndx_d0YaDSviDfpzwN9T46dQrV9WbeG8YH9KVBg,2466
|
|
@@ -31,7 +32,7 @@ muffin_rest/sqlalchemy/types.py,sha256=JnIw44XJ2ClWzOv-mTUrvFw1JPxAlvdX_jf7r4zau
|
|
|
31
32
|
muffin_rest/swagger.html,sha256=2uGLu_KpkYf925KnDKHBJmV9pm6OHn5C3BWScESsUS8,1736
|
|
32
33
|
muffin_rest/types.py,sha256=vy55ShzMcvs9zXjFpdjWlagv09dMrcmxb2-U4hTL3NM,521
|
|
33
34
|
muffin_rest/utils.py,sha256=WT87AHXvBFBzBVTkwsYmDXgG3ZX1wNKFo4SOUJ9JiQY,2095
|
|
34
|
-
muffin_rest-7.3.
|
|
35
|
-
muffin_rest-7.3.
|
|
36
|
-
muffin_rest-7.3.
|
|
37
|
-
muffin_rest-7.3.
|
|
35
|
+
muffin_rest-7.3.4.dist-info/LICENSE,sha256=xHPkOZhjyKBMOwXpWn9IB_BVLjrrMxv2M9slKkHj2hM,1082
|
|
36
|
+
muffin_rest-7.3.4.dist-info/METADATA,sha256=bvw-BTahZcC0_w6SdPkpcpWhnH9jwqM14G6ybxLAfqU,4177
|
|
37
|
+
muffin_rest-7.3.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
38
|
+
muffin_rest-7.3.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|