muffin-rest 7.3.2__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/filters.py +2 -2
- muffin_rest/peewee/options.py +3 -3
- muffin_rest/peewee/schemas.py +1 -25
- muffin_rest/schemas.py +27 -0
- muffin_rest/sqlalchemy/__init__.py +2 -2
- {muffin_rest-7.3.2.dist-info → muffin_rest-7.3.4.dist-info}/METADATA +2 -1
- {muffin_rest-7.3.2.dist-info → muffin_rest-7.3.4.dist-info}/RECORD +9 -8
- {muffin_rest-7.3.2.dist-info → muffin_rest-7.3.4.dist-info}/WHEEL +1 -1
- {muffin_rest-7.3.2.dist-info → muffin_rest-7.3.4.dist-info}/LICENSE +0 -0
muffin_rest/filters.py
CHANGED
|
@@ -38,9 +38,9 @@ class Filter(Mutate):
|
|
|
38
38
|
"$nor": lambda v, c: not any(f(v, c) for f in v),
|
|
39
39
|
}
|
|
40
40
|
operators["<"] = operators["$lt"]
|
|
41
|
-
operators["<="] = operators["$le"]
|
|
41
|
+
operators["<="] = operators["$lte"] = operators["$le"]
|
|
42
42
|
operators[">"] = operators["$gt"]
|
|
43
|
-
operators[">="] = operators["$ge"]
|
|
43
|
+
operators[">="] = operators["$gte"] = operators["$ge"]
|
|
44
44
|
operators["=="] = operators["$eq"]
|
|
45
45
|
operators["!="] = operators["$ne"]
|
|
46
46
|
operators["<<"] = operators["$in"]
|
muffin_rest/peewee/options.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Type
|
|
2
2
|
|
|
3
3
|
import peewee as pw
|
|
4
4
|
from marshmallow_peewee import ModelSchema
|
|
@@ -27,7 +27,7 @@ class PWRESTOptions(RESTOptions):
|
|
|
27
27
|
base_property: str = "model"
|
|
28
28
|
|
|
29
29
|
model: Type[pw.Model]
|
|
30
|
-
model_pk:
|
|
30
|
+
model_pk: pw.Field
|
|
31
31
|
|
|
32
32
|
manager: Manager
|
|
33
33
|
|
|
@@ -38,7 +38,7 @@ class PWRESTOptions(RESTOptions):
|
|
|
38
38
|
"""Prepare meta options."""
|
|
39
39
|
meta = self.model._meta # type: ignore[]
|
|
40
40
|
self.name = self.name or meta.table_name.lower()
|
|
41
|
-
self.model_pk = self
|
|
41
|
+
self.model_pk = getattr(self, "model_pk", None) or meta.primary_key
|
|
42
42
|
manager = getattr(self, "manager", getattr(self.model, "_manager", None))
|
|
43
43
|
if manager is None:
|
|
44
44
|
raise RuntimeError("Peewee-AIO ORM Manager is not available")
|
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
|
|
@@ -77,7 +77,7 @@ class SARESTOptions(RESTOptions):
|
|
|
77
77
|
schema_base: Type[SQLAlchemyAutoSchema] = SQLAlchemyAutoSchema
|
|
78
78
|
|
|
79
79
|
table: sa.Table
|
|
80
|
-
table_pk:
|
|
80
|
+
table_pk: sa.Column
|
|
81
81
|
database: Database
|
|
82
82
|
|
|
83
83
|
base_property = "table"
|
|
@@ -88,7 +88,7 @@ class SARESTOptions(RESTOptions):
|
|
|
88
88
|
raise ValueError("'SARESTHandler.Meta.database' is required")
|
|
89
89
|
|
|
90
90
|
self.name = self.name or self.table.name
|
|
91
|
-
self.table_pk = self
|
|
91
|
+
self.table_pk = getattr(self, "table_pk", None) or self.table.c.id
|
|
92
92
|
|
|
93
93
|
super().setup(cls)
|
|
94
94
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: muffin-rest
|
|
3
|
-
Version: 7.3.
|
|
3
|
+
Version: 7.3.4
|
|
4
4
|
Summary: The package provides enhanced support for writing REST APIs with Muffin framework
|
|
5
5
|
Home-page: https://github.com/klen/muffin-rest
|
|
6
6
|
License: MIT
|
|
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.9
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
23
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
23
24
|
Provides-Extra: peewee
|
|
24
25
|
Provides-Extra: sqlalchemy
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
muffin_rest/__init__.py,sha256=NBZeOEJgQHtFFhVgd9d0fpApFRgU405sbm0cu1y1MOU,1242
|
|
2
2
|
muffin_rest/api.py,sha256=gCqRb5PgKEMkE84Y0ZnJw_laVRmVWZRxzBqBv0ns6w8,3882
|
|
3
3
|
muffin_rest/errors.py,sha256=TIXSADZYSwx70dOVPRAzuNwGLfpLuzZZ1ugMZMwIGDo,1169
|
|
4
|
-
muffin_rest/filters.py,sha256=
|
|
4
|
+
muffin_rest/filters.py,sha256=lMnPMdy7h0nB9bH-Nf5Hv_qenAGzG0V3ULpizTK3OnM,5623
|
|
5
5
|
muffin_rest/handler.py,sha256=LcPFFH01nwe2tYKYbq-KVDX5UBVMlaRmeisJ_s4jsCo,10035
|
|
6
6
|
muffin_rest/marshmallow.py,sha256=hHPLTLdaSz5jTLWBqyHeOwo2xfBv7aMIuJFD_trHRuE,715
|
|
7
7
|
muffin_rest/mongo/__init__.py,sha256=unoEAKCU9H3EKhQqKGosn02tTS3H5nPOcTd3THM4Qs8,4675
|
|
@@ -16,22 +16,23 @@ muffin_rest/peewee/__init__.py,sha256=94DSj_ftT6fbPksHlBv40AH2HWaiZommUFOMN2jd9a
|
|
|
16
16
|
muffin_rest/peewee/filters.py,sha256=ziqpD7uH9vzx_yHKUpOYmduNmM8w-8b7CtRaSoCqECU,2382
|
|
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
|
-
muffin_rest/peewee/options.py,sha256=
|
|
20
|
-
muffin_rest/peewee/schemas.py,sha256=
|
|
19
|
+
muffin_rest/peewee/options.py,sha256=F-UjCbz5rAIXt-D_MtmriiYkOL7wsri6FRt7WCNZzyo,1480
|
|
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
|
-
muffin_rest/sqlalchemy/__init__.py,sha256=
|
|
28
|
+
muffin_rest/sqlalchemy/__init__.py,sha256=WYxb5d4eQqXeT8MwpgdiItAjrOdFm-_5GaG-xtWQ4lk,6362
|
|
28
29
|
muffin_rest/sqlalchemy/filters.py,sha256=bTT7ndx_d0YaDSviDfpzwN9T46dQrV9WbeG8YH9KVBg,2466
|
|
29
30
|
muffin_rest/sqlalchemy/sorting.py,sha256=YlFKpIet4TUy7fJ2UBLC8b9lAOwY66QBpPDDApbyh8M,1643
|
|
30
31
|
muffin_rest/sqlalchemy/types.py,sha256=JnIw44XJ2ClWzOv-mTUrvFw1JPxAlvdX_jf7r4zau-s,204
|
|
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
|