ramifice 0.8.22__py3-none-any.whl → 0.8.25__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.
- ramifice/__init__.py +8 -1
- ramifice/commons/__init__.py +2 -2
- ramifice/commons/general.py +11 -11
- ramifice/commons/indexes.py +8 -8
- ramifice/commons/many.py +6 -6
- ramifice/commons/one.py +8 -8
- ramifice/commons/tools.py +4 -4
- ramifice/commons/unit_manager.py +3 -3
- ramifice/fields/__init__.py +1 -1
- ramifice/fields/bool_field.py +4 -4
- ramifice/fields/choice_float_dyn_field.py +5 -5
- ramifice/fields/choice_float_field.py +5 -5
- ramifice/fields/choice_float_mult_dyn_field.py +5 -5
- ramifice/fields/choice_float_mult_field.py +5 -5
- ramifice/fields/choice_int_dyn_field.py +5 -5
- ramifice/fields/choice_int_field.py +5 -5
- ramifice/fields/choice_int_mult_dyn_field.py +5 -5
- ramifice/fields/choice_int_mult_field.py +5 -5
- ramifice/fields/choice_text_dyn_field.py +5 -5
- ramifice/fields/choice_text_field.py +5 -5
- ramifice/fields/choice_text_mult_dyn_field.py +5 -5
- ramifice/fields/choice_text_mult_field.py +5 -5
- ramifice/fields/color_field.py +4 -4
- ramifice/fields/date_field.py +7 -7
- ramifice/fields/date_time_field.py +7 -7
- ramifice/fields/email_field.py +4 -4
- ramifice/fields/file_field.py +6 -6
- ramifice/fields/float_field.py +4 -4
- ramifice/fields/general/__init__.py +1 -1
- ramifice/fields/general/choice_group.py +9 -10
- ramifice/fields/general/date_group.py +11 -11
- ramifice/fields/general/field.py +13 -13
- ramifice/fields/general/file_group.py +10 -10
- ramifice/fields/general/number_group.py +8 -8
- ramifice/fields/general/text_group.py +10 -10
- ramifice/fields/id_field.py +7 -7
- ramifice/fields/image_field.py +6 -6
- ramifice/fields/integer_field.py +4 -4
- ramifice/fields/ip_field.py +4 -4
- ramifice/fields/password_field.py +7 -7
- ramifice/fields/phone_field.py +4 -4
- ramifice/fields/slug_field.py +4 -4
- ramifice/fields/text_field.py +5 -5
- ramifice/fields/url_field.py +4 -4
- ramifice/models/__init__.py +1 -1
- ramifice/models/decorator.py +3 -3
- ramifice/models/model.py +16 -16
- ramifice/paladins/__init__.py +2 -2
- ramifice/paladins/add_valid.py +3 -3
- ramifice/paladins/check.py +3 -3
- ramifice/paladins/delete.py +3 -3
- ramifice/paladins/groups/__init__.py +1 -1
- ramifice/paladins/groups/bool_group.py +3 -3
- ramifice/paladins/groups/choice_group.py +3 -3
- ramifice/paladins/groups/date_group.py +3 -3
- ramifice/paladins/groups/file_group.py +3 -3
- ramifice/paladins/groups/id_group.py +3 -3
- ramifice/paladins/groups/img_group.py +3 -3
- ramifice/paladins/groups/num_group.py +3 -3
- ramifice/paladins/groups/pass_group.py +3 -3
- ramifice/paladins/groups/slug_group.py +3 -3
- ramifice/paladins/groups/text_group.py +3 -3
- ramifice/paladins/hooks.py +8 -8
- ramifice/paladins/indexing.py +3 -3
- ramifice/paladins/password.py +4 -4
- ramifice/paladins/refrash.py +3 -3
- ramifice/paladins/save.py +3 -3
- ramifice/paladins/tools.py +6 -6
- ramifice/paladins/validation.py +4 -4
- ramifice/utils/__init__.py +13 -1
- ramifice/utils/constants.py +1 -1
- ramifice/utils/errors.py +23 -23
- ramifice/utils/fixtures.py +2 -2
- ramifice/utils/migration.py +8 -8
- ramifice/utils/{mixins/json_converter.py → mixins.py} +6 -6
- ramifice/utils/tools.py +12 -12
- ramifice/utils/translations.py +5 -5
- ramifice/utils/unit.py +10 -10
- {ramifice-0.8.22.dist-info → ramifice-0.8.25.dist-info}/METADATA +3 -2
- ramifice-0.8.25.dist-info/RECORD +83 -0
- ramifice/utils/mixins/__init__.py +0 -5
- ramifice-0.8.22.dist-info/RECORD +0 -84
- {ramifice-0.8.22.dist-info → ramifice-0.8.25.dist-info}/WHEEL +0 -0
- {ramifice-0.8.22.dist-info → ramifice-0.8.25.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""General additional parameters for number fields."""
|
2
2
|
|
3
3
|
__all__ = ("NumberGroup",)
|
4
4
|
|
@@ -6,13 +6,13 @@ from abc import ABCMeta
|
|
6
6
|
|
7
7
|
|
8
8
|
class NumberGroup(metaclass=ABCMeta):
|
9
|
-
"""
|
9
|
+
"""General additional parameters for number fields.
|
10
10
|
|
11
|
-
|
12
|
-
placeholder
|
13
|
-
required
|
14
|
-
readonly
|
15
|
-
unique
|
11
|
+
Args:
|
12
|
+
placeholder: Displays prompt text.
|
13
|
+
required: Required field.
|
14
|
+
readonly: Specifies that the field cannot be modified by the user.
|
15
|
+
unique: The unique value of a field in a collection.
|
16
16
|
"""
|
17
17
|
|
18
18
|
def __init__( # noqa: D107
|
@@ -21,7 +21,7 @@ class NumberGroup(metaclass=ABCMeta):
|
|
21
21
|
required: bool = False,
|
22
22
|
readonly: bool = False,
|
23
23
|
unique: bool = False,
|
24
|
-
):
|
24
|
+
) -> None:
|
25
25
|
self.placeholder = placeholder
|
26
26
|
self.required = required
|
27
27
|
self.readonly = readonly
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""General additional parameters for text fields."""
|
2
2
|
|
3
3
|
__all__ = ("TextGroup",)
|
4
4
|
|
@@ -6,14 +6,14 @@ from abc import ABCMeta
|
|
6
6
|
|
7
7
|
|
8
8
|
class TextGroup(metaclass=ABCMeta):
|
9
|
-
"""
|
9
|
+
"""General additional parameters for text fields.
|
10
10
|
|
11
|
-
|
12
|
-
input_type
|
13
|
-
placeholder
|
14
|
-
required
|
15
|
-
readonly
|
16
|
-
unique
|
11
|
+
Args:
|
12
|
+
input_type: Input type for a web form field.
|
13
|
+
placeholder: Displays prompt text.
|
14
|
+
required: Required field.
|
15
|
+
readonly: Specifies that the field cannot be modified by the user.
|
16
|
+
unique: The unique value of a field in a collection.
|
17
17
|
"""
|
18
18
|
|
19
19
|
def __init__( # noqa: D107
|
@@ -23,7 +23,7 @@ class TextGroup(metaclass=ABCMeta):
|
|
23
23
|
required: bool = False,
|
24
24
|
readonly: bool = False,
|
25
25
|
unique: bool = False,
|
26
|
-
):
|
26
|
+
) -> None:
|
27
27
|
self.input_type = input_type
|
28
28
|
self.value: str | None = None
|
29
29
|
self.placeholder = placeholder
|
@@ -32,7 +32,7 @@ class TextGroup(metaclass=ABCMeta):
|
|
32
32
|
self.unique = unique
|
33
33
|
|
34
34
|
def __len__(self) -> int:
|
35
|
-
"""
|
35
|
+
"""Return length of field `value`."""
|
36
36
|
value = self.value
|
37
37
|
if value is None:
|
38
38
|
return 0
|
ramifice/fields/id_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for enter identifier of document."""
|
2
2
|
|
3
3
|
__all__ = ("IDField",)
|
4
4
|
|
@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
|
|
15
15
|
|
16
16
|
|
17
17
|
class IDField(Field):
|
18
|
-
"""
|
18
|
+
"""Field of Model for enter identifier of document.
|
19
19
|
|
20
20
|
Attributes:
|
21
21
|
input_type -- Input type for a web form field.
|
@@ -37,7 +37,7 @@ class IDField(Field):
|
|
37
37
|
required: bool = False,
|
38
38
|
readonly: bool = False,
|
39
39
|
unique: bool = False,
|
40
|
-
):
|
40
|
+
) -> None:
|
41
41
|
if constants.DEBUG:
|
42
42
|
try:
|
43
43
|
if not isinstance(label, str):
|
@@ -87,7 +87,7 @@ class IDField(Field):
|
|
87
87
|
self.alerts: list[str] = []
|
88
88
|
|
89
89
|
def to_dict(self) -> dict[str, Any]:
|
90
|
-
"""
|
90
|
+
"""Convert object instance to a dictionary."""
|
91
91
|
json_dict: dict[str, Any] = {}
|
92
92
|
for name, data in self.__dict__.items():
|
93
93
|
if not callable(data):
|
@@ -98,12 +98,12 @@ class IDField(Field):
|
|
98
98
|
return json_dict
|
99
99
|
|
100
100
|
def to_json(self) -> str:
|
101
|
-
"""
|
101
|
+
"""Convert object instance to a JSON string."""
|
102
102
|
return orjson.dumps(self.to_dict()).decode("utf-8")
|
103
103
|
|
104
104
|
@classmethod
|
105
105
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
106
|
-
"""
|
106
|
+
"""Convert JSON string to a object instance."""
|
107
107
|
obj = cls()
|
108
108
|
for name, data in json_dict.items():
|
109
109
|
if name == "value" and data is not None:
|
@@ -114,6 +114,6 @@ class IDField(Field):
|
|
114
114
|
|
115
115
|
@classmethod
|
116
116
|
def from_json(cls, json_str: str) -> Any:
|
117
|
-
"""
|
117
|
+
"""Convert JSON string to a object instance."""
|
118
118
|
json_dict = orjson.loads(json_str)
|
119
119
|
return cls.from_dict(json_dict)
|
ramifice/fields/image_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for upload image."""
|
2
2
|
|
3
3
|
__all__ = ("ImageField",)
|
4
4
|
|
@@ -17,13 +17,13 @@ from ramifice.fields.general.file_group import FileGroup
|
|
17
17
|
from ramifice.utils import constants
|
18
18
|
from ramifice.utils.constants import MEDIA_ROOT, MEDIA_URL
|
19
19
|
from ramifice.utils.errors import FileHasNoExtensionError
|
20
|
-
from ramifice.utils.mixins
|
20
|
+
from ramifice.utils.mixins import JsonMixin
|
21
21
|
|
22
22
|
logger = logging.getLogger(__name__)
|
23
23
|
|
24
24
|
|
25
25
|
class ImageField(Field, FileGroup, JsonMixin):
|
26
|
-
"""
|
26
|
+
"""Field of Model for upload image."""
|
27
27
|
|
28
28
|
def __init__( # noqa: D107
|
29
29
|
self,
|
@@ -43,7 +43,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
43
43
|
# Available 4 sizes from lg to xs or None.
|
44
44
|
# Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
|
45
45
|
thumbnails: dict[str, int] | None = None,
|
46
|
-
):
|
46
|
+
) -> None:
|
47
47
|
if constants.DEBUG:
|
48
48
|
try:
|
49
49
|
if default is not None:
|
@@ -139,7 +139,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
139
139
|
filename: str | None = None,
|
140
140
|
is_delete: bool = False,
|
141
141
|
) -> None:
|
142
|
-
"""
|
142
|
+
"""Convert base64 to a image,
|
143
143
|
get image information and save in the target directory.
|
144
144
|
""" # noqa: D205
|
145
145
|
base64_str = base64_str or None
|
@@ -208,7 +208,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
208
208
|
src_path: str | None = None,
|
209
209
|
is_delete: bool = False,
|
210
210
|
) -> None:
|
211
|
-
"""
|
211
|
+
"""Get image information and copy the image to the target directory."""
|
212
212
|
src_path = src_path or None
|
213
213
|
img_info: dict[str, str | int | bool] = {"save_as_is": False}
|
214
214
|
img_info["is_new_img"] = True
|
ramifice/fields/integer_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for enter (int) number."""
|
2
2
|
|
3
3
|
__all__ = ("IntegerField",)
|
4
4
|
|
@@ -8,13 +8,13 @@ from typing import Literal
|
|
8
8
|
from ramifice.fields.general.field import Field
|
9
9
|
from ramifice.fields.general.number_group import NumberGroup
|
10
10
|
from ramifice.utils import constants
|
11
|
-
from ramifice.utils.mixins
|
11
|
+
from ramifice.utils.mixins import JsonMixin
|
12
12
|
|
13
13
|
logger = logging.getLogger(__name__)
|
14
14
|
|
15
15
|
|
16
16
|
class IntegerField(Field, NumberGroup, JsonMixin):
|
17
|
-
"""
|
17
|
+
"""Field of Model for enter (int) number."""
|
18
18
|
|
19
19
|
def __init__( # noqa: D107
|
20
20
|
self,
|
@@ -33,7 +33,7 @@ class IntegerField(Field, NumberGroup, JsonMixin):
|
|
33
33
|
min_number: int | None = None,
|
34
34
|
step: int = 1,
|
35
35
|
input_type: Literal["number", "range"] = "number",
|
36
|
-
):
|
36
|
+
) -> None:
|
37
37
|
if constants.DEBUG:
|
38
38
|
try:
|
39
39
|
if input_type not in ["number", "range"]:
|
ramifice/fields/ip_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for enter IP address."""
|
2
2
|
|
3
3
|
__all__ = ("IPField",)
|
4
4
|
|
@@ -8,13 +8,13 @@ import logging
|
|
8
8
|
from ramifice.fields.general.field import Field
|
9
9
|
from ramifice.fields.general.text_group import TextGroup
|
10
10
|
from ramifice.utils import constants
|
11
|
-
from ramifice.utils.mixins
|
11
|
+
from ramifice.utils.mixins import JsonMixin
|
12
12
|
|
13
13
|
logger = logging.getLogger(__name__)
|
14
14
|
|
15
15
|
|
16
16
|
class IPField(Field, TextGroup, JsonMixin):
|
17
|
-
"""
|
17
|
+
"""Field of Model for enter IP address."""
|
18
18
|
|
19
19
|
def __init__( # noqa: D107
|
20
20
|
self,
|
@@ -29,7 +29,7 @@ class IPField(Field, TextGroup, JsonMixin):
|
|
29
29
|
required: bool = False,
|
30
30
|
readonly: bool = False,
|
31
31
|
unique: bool = False,
|
32
|
-
):
|
32
|
+
) -> None:
|
33
33
|
if constants.DEBUG:
|
34
34
|
try:
|
35
35
|
if default is not None:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for enter password."""
|
2
2
|
|
3
3
|
__all__ = ("PasswordField",)
|
4
4
|
|
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
|
|
14
14
|
|
15
15
|
|
16
16
|
class PasswordField(Field):
|
17
|
-
r"""
|
17
|
+
r"""Field of Model for enter password.
|
18
18
|
|
19
19
|
Warning:
|
20
20
|
Regular expression: ^[-._!"`'#%&,:;<>=@{}~$()*+/\\?[]^|a-zA-Z0-9]{8,256}$
|
@@ -31,7 +31,7 @@ class PasswordField(Field):
|
|
31
31
|
warning: list[str] | None = None,
|
32
32
|
placeholder: str = "",
|
33
33
|
required: bool = False,
|
34
|
-
):
|
34
|
+
) -> None:
|
35
35
|
if constants.DEBUG:
|
36
36
|
try:
|
37
37
|
if not isinstance(label, str):
|
@@ -72,7 +72,7 @@ class PasswordField(Field):
|
|
72
72
|
self.required = required
|
73
73
|
|
74
74
|
def to_dict(self) -> dict[str, Any]:
|
75
|
-
"""
|
75
|
+
"""Convert object instance to a dictionary."""
|
76
76
|
json_dict: dict[str, Any] = {}
|
77
77
|
for name, data in self.__dict__.items():
|
78
78
|
if not callable(data):
|
@@ -80,12 +80,12 @@ class PasswordField(Field):
|
|
80
80
|
return json_dict
|
81
81
|
|
82
82
|
def to_json(self) -> str:
|
83
|
-
"""
|
83
|
+
"""Convert object instance to a JSON string."""
|
84
84
|
return orjson.dumps(self.to_dict()).decode("utf-8")
|
85
85
|
|
86
86
|
@classmethod
|
87
87
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
88
|
-
"""
|
88
|
+
"""Convert JSON string to a object instance."""
|
89
89
|
obj = cls()
|
90
90
|
for name, data in json_dict.items():
|
91
91
|
obj.__dict__[name] = data
|
@@ -93,6 +93,6 @@ class PasswordField(Field):
|
|
93
93
|
|
94
94
|
@classmethod
|
95
95
|
def from_json(cls, json_str: str) -> Any:
|
96
|
-
"""
|
96
|
+
"""Convert JSON string to a object instance."""
|
97
97
|
json_dict = orjson.loads(json_str)
|
98
98
|
return cls.from_dict(json_dict)
|
ramifice/fields/phone_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for enter phone number."""
|
2
2
|
|
3
3
|
__all__ = ("PhoneField",)
|
4
4
|
|
@@ -9,13 +9,13 @@ import phonenumbers
|
|
9
9
|
from ramifice.fields.general.field import Field
|
10
10
|
from ramifice.fields.general.text_group import TextGroup
|
11
11
|
from ramifice.utils import constants
|
12
|
-
from ramifice.utils.mixins
|
12
|
+
from ramifice.utils.mixins import JsonMixin
|
13
13
|
|
14
14
|
logger = logging.getLogger(__name__)
|
15
15
|
|
16
16
|
|
17
17
|
class PhoneField(Field, TextGroup, JsonMixin):
|
18
|
-
"""
|
18
|
+
"""Field of Model for enter phone number.
|
19
19
|
|
20
20
|
WARNING: By default is used validator `phonenumbers.is_valid_number()`.
|
21
21
|
"""
|
@@ -33,7 +33,7 @@ class PhoneField(Field, TextGroup, JsonMixin):
|
|
33
33
|
required: bool = False,
|
34
34
|
readonly: bool = False,
|
35
35
|
unique: bool = False,
|
36
|
-
):
|
36
|
+
) -> None:
|
37
37
|
if constants.DEBUG:
|
38
38
|
try:
|
39
39
|
if default is not None:
|
ramifice/fields/slug_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for automatic generation of string `slug`."""
|
2
2
|
|
3
3
|
__all__ = ("SlugField",)
|
4
4
|
|
@@ -7,13 +7,13 @@ import logging
|
|
7
7
|
from ramifice.fields.general.field import Field
|
8
8
|
from ramifice.fields.general.text_group import TextGroup
|
9
9
|
from ramifice.utils import constants
|
10
|
-
from ramifice.utils.mixins
|
10
|
+
from ramifice.utils.mixins import JsonMixin
|
11
11
|
|
12
12
|
logger = logging.getLogger(__name__)
|
13
13
|
|
14
14
|
|
15
15
|
class SlugField(Field, TextGroup, JsonMixin):
|
16
|
-
"""
|
16
|
+
"""Field of Model for automatic generation of string `slug`.
|
17
17
|
|
18
18
|
Convenient to use for Url addresses.
|
19
19
|
"""
|
@@ -29,7 +29,7 @@ class SlugField(Field, TextGroup, JsonMixin):
|
|
29
29
|
placeholder: str = "",
|
30
30
|
readonly: bool = False,
|
31
31
|
slug_sources: list[str] = ["_id"],
|
32
|
-
):
|
32
|
+
) -> None:
|
33
33
|
if constants.DEBUG:
|
34
34
|
try:
|
35
35
|
if not isinstance(label, str):
|
ramifice/fields/text_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for enter text."""
|
2
2
|
|
3
3
|
__all__ = ("TextField",)
|
4
4
|
|
@@ -6,13 +6,13 @@ import logging
|
|
6
6
|
|
7
7
|
from ramifice.fields.general.field import Field
|
8
8
|
from ramifice.utils import constants
|
9
|
-
from ramifice.utils.mixins
|
9
|
+
from ramifice.utils.mixins import JsonMixin
|
10
10
|
|
11
11
|
logger = logging.getLogger(__name__)
|
12
12
|
|
13
13
|
|
14
14
|
class TextField(Field, JsonMixin):
|
15
|
-
"""
|
15
|
+
"""Field of Model for enter text."""
|
16
16
|
|
17
17
|
def __init__( # noqa: D107
|
18
18
|
self,
|
@@ -31,7 +31,7 @@ class TextField(Field, JsonMixin):
|
|
31
31
|
maxlength: int = 256,
|
32
32
|
# Support for several language.
|
33
33
|
multi_language: bool = False,
|
34
|
-
):
|
34
|
+
) -> None:
|
35
35
|
if constants.DEBUG:
|
36
36
|
try:
|
37
37
|
if not isinstance(maxlength, int):
|
@@ -96,7 +96,7 @@ class TextField(Field, JsonMixin):
|
|
96
96
|
self.multi_language = multi_language
|
97
97
|
|
98
98
|
def __len__(self) -> int:
|
99
|
-
"""
|
99
|
+
"""Return length of field `value`."""
|
100
100
|
value = self.value
|
101
101
|
if isinstance(value, str):
|
102
102
|
return len(value)
|
ramifice/fields/url_field.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Field of Model for enter URL address."""
|
2
2
|
|
3
3
|
__all__ = ("URLField",)
|
4
4
|
|
@@ -8,13 +8,13 @@ from urllib.parse import urlparse
|
|
8
8
|
from ramifice.fields.general.field import Field
|
9
9
|
from ramifice.fields.general.text_group import TextGroup
|
10
10
|
from ramifice.utils import constants
|
11
|
-
from ramifice.utils.mixins
|
11
|
+
from ramifice.utils.mixins import JsonMixin
|
12
12
|
|
13
13
|
logger = logging.getLogger(__name__)
|
14
14
|
|
15
15
|
|
16
16
|
class URLField(Field, TextGroup, JsonMixin):
|
17
|
-
"""
|
17
|
+
"""Field of Model for enter URL address.
|
18
18
|
|
19
19
|
Attributes:
|
20
20
|
label -- Text label for a web form field.
|
@@ -43,7 +43,7 @@ class URLField(Field, TextGroup, JsonMixin):
|
|
43
43
|
required: bool = False,
|
44
44
|
readonly: bool = False,
|
45
45
|
unique: bool = False,
|
46
|
-
):
|
46
|
+
) -> None:
|
47
47
|
if constants.DEBUG:
|
48
48
|
try:
|
49
49
|
if default is not None:
|
ramifice/models/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"""
|
1
|
+
"""Models."""
|
ramifice/models/decorator.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Decorator for converting Python classes into Ramifice models."""
|
2
2
|
|
3
3
|
__all__ = ("model",)
|
4
4
|
|
@@ -25,7 +25,7 @@ def model(
|
|
25
25
|
is_update_doc: bool = True,
|
26
26
|
is_delete_doc: bool = True,
|
27
27
|
) -> Any:
|
28
|
-
"""
|
28
|
+
"""Decorator for converting Python Classe into Ramifice Model."""
|
29
29
|
try:
|
30
30
|
if not isinstance(service_name, str):
|
31
31
|
msg = "Parameter `service_name` - Must be `str` type!"
|
@@ -96,7 +96,7 @@ def model(
|
|
96
96
|
|
97
97
|
|
98
98
|
def caching(cls: Any, service_name: str) -> dict[str, Any]:
|
99
|
-
"""
|
99
|
+
"""Add additional metadata to `Model.META`."""
|
100
100
|
metadata: dict[str, Any] = {}
|
101
101
|
model_name: str = cls.__name__
|
102
102
|
if REGEX["model_name"].match(model_name) is None:
|
ramifice/models/model.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Converting Python classes into Ramifice Models."""
|
2
2
|
|
3
3
|
__all__ = ("Model",)
|
4
4
|
|
@@ -16,7 +16,7 @@ from ramifice.utils import translations
|
|
16
16
|
|
17
17
|
|
18
18
|
class Model(metaclass=ABCMeta):
|
19
|
-
"""
|
19
|
+
"""Converting Python Class into Ramifice Model."""
|
20
20
|
|
21
21
|
META: dict[str, Any] = {}
|
22
22
|
|
@@ -50,25 +50,25 @@ class Model(metaclass=ABCMeta):
|
|
50
50
|
|
51
51
|
@property
|
52
52
|
def id(self) -> IDField:
|
53
|
-
"""
|
53
|
+
"""Getter for the field `_id`."""
|
54
54
|
return self._id
|
55
55
|
|
56
56
|
@abstractmethod
|
57
57
|
def fields(self) -> None:
|
58
|
-
"""
|
58
|
+
"""Adding fields."""
|
59
59
|
pass
|
60
60
|
|
61
61
|
def model_name(self) -> str:
|
62
|
-
"""
|
62
|
+
"""Get Model name - Class name."""
|
63
63
|
return self.__class__.__name__
|
64
64
|
|
65
65
|
def full_model_name(self) -> str:
|
66
|
-
"""
|
66
|
+
"""Get full Model name - module_name + . + ClassName."""
|
67
67
|
cls = self.__class__
|
68
68
|
return f"{cls.__module__}.{cls.__name__}"
|
69
69
|
|
70
70
|
def inject(self) -> None:
|
71
|
-
"""
|
71
|
+
"""Injecting metadata from Model.META in params of fields."""
|
72
72
|
metadata = self.__class__.META
|
73
73
|
if bool(metadata):
|
74
74
|
lang = translations.CURRENT_LOCALE
|
@@ -92,7 +92,7 @@ class Model(metaclass=ABCMeta):
|
|
92
92
|
# Complect of methods for converting Model to JSON and back.
|
93
93
|
# --------------------------------------------------------------------------
|
94
94
|
def to_dict(self) -> dict[str, Any]:
|
95
|
-
"""
|
95
|
+
"""Convert object instance to a dictionary."""
|
96
96
|
json_dict: dict[str, Any] = {}
|
97
97
|
for name, data in self.__dict__.items():
|
98
98
|
if not callable(data):
|
@@ -100,12 +100,12 @@ class Model(metaclass=ABCMeta):
|
|
100
100
|
return json_dict
|
101
101
|
|
102
102
|
def to_json(self) -> str:
|
103
|
-
"""
|
103
|
+
"""Convert object instance to a JSON string."""
|
104
104
|
return orjson.dumps(self.to_dict()).decode("utf-8")
|
105
105
|
|
106
106
|
@classmethod
|
107
107
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
108
|
-
"""
|
108
|
+
"""Convert JSON string to a object instance."""
|
109
109
|
obj = cls()
|
110
110
|
for name, data in json_dict.items():
|
111
111
|
obj.__dict__[name] = obj.__dict__[name].__class__.from_dict(data)
|
@@ -113,13 +113,13 @@ class Model(metaclass=ABCMeta):
|
|
113
113
|
|
114
114
|
@classmethod
|
115
115
|
def from_json(cls, json_str: str) -> Any:
|
116
|
-
"""
|
116
|
+
"""Convert JSON string to a object instance."""
|
117
117
|
json_dict = orjson.loads(json_str)
|
118
118
|
return cls.from_dict(json_dict)
|
119
119
|
|
120
120
|
# --------------------------------------------------------------------------
|
121
121
|
def to_dict_only_value(self) -> dict[str, Any]:
|
122
|
-
"""
|
122
|
+
"""Convert model.field.value (only the `value` attribute) to a dictionary."""
|
123
123
|
json_dict: dict[str, Any] = {}
|
124
124
|
current_locale = translations.CURRENT_LOCALE
|
125
125
|
for name, data in self.__dict__.items():
|
@@ -150,12 +150,12 @@ class Model(metaclass=ABCMeta):
|
|
150
150
|
return json_dict
|
151
151
|
|
152
152
|
def to_json_only_value(self) -> str:
|
153
|
-
"""
|
153
|
+
"""Convert model.field.value (only the `value` attribute) to a JSON string."""
|
154
154
|
return orjson.dumps(self.to_dict_only_value()).decode("utf-8")
|
155
155
|
|
156
156
|
@classmethod
|
157
157
|
def from_dict_only_value(cls, json_dict: dict[str, Any]) -> Any:
|
158
|
-
"""
|
158
|
+
"""Convert JSON string to a object instance."""
|
159
159
|
obj = cls()
|
160
160
|
for name, data in obj.__dict__.items():
|
161
161
|
if callable(data):
|
@@ -172,12 +172,12 @@ class Model(metaclass=ABCMeta):
|
|
172
172
|
|
173
173
|
@classmethod
|
174
174
|
def from_json_only_value(cls, json_str: str) -> Any:
|
175
|
-
"""
|
175
|
+
"""Convert JSON string to a object instance."""
|
176
176
|
json_dict = orjson.loads(json_str)
|
177
177
|
return cls.from_dict_only_value(json_dict)
|
178
178
|
|
179
179
|
def refrash_fields_only_value(self, only_value_dict: dict[str, Any]) -> None:
|
180
|
-
"""
|
180
|
+
"""Partial or complete update a `value` of fields."""
|
181
181
|
for name, data in self.__dict__.items():
|
182
182
|
if callable(data):
|
183
183
|
continue
|
ramifice/paladins/__init__.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Paladins - Model instance methods."""
|
2
2
|
|
3
3
|
__all__ = ("QPaladinsMixin",)
|
4
4
|
|
@@ -24,7 +24,7 @@ class QPaladinsMixin(
|
|
24
24
|
HooksMixin,
|
25
25
|
IndexMixin,
|
26
26
|
):
|
27
|
-
"""
|
27
|
+
"""Paladins - Model instance methods."""
|
28
28
|
|
29
29
|
def __init__(self) -> None: # noqa: D107
|
30
30
|
super().__init__()
|
ramifice/paladins/add_valid.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""AddValidMixin - Contains an abstract method for additional validation of fields."""
|
2
2
|
|
3
3
|
__all__ = ("AddValidMixin",)
|
4
4
|
|
@@ -8,8 +8,8 @@ from xloft import NamedTuple
|
|
8
8
|
|
9
9
|
|
10
10
|
class AddValidMixin(metaclass=ABCMeta):
|
11
|
-
"""
|
11
|
+
"""Contains an abstract method for additional validation of fields."""
|
12
12
|
|
13
13
|
async def add_validation(self) -> NamedTuple:
|
14
|
-
"""
|
14
|
+
"""Additional validation of fields."""
|
15
15
|
return NamedTuple()
|
ramifice/paladins/check.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Validation of Model data before saving to the database."""
|
2
2
|
|
3
3
|
__all__ = ("CheckMixin",)
|
4
4
|
|
@@ -40,7 +40,7 @@ class CheckMixin(
|
|
40
40
|
SlugGroupMixin,
|
41
41
|
TextGroupMixin,
|
42
42
|
):
|
43
|
-
"""
|
43
|
+
"""Validation of Model data before saving to the database."""
|
44
44
|
|
45
45
|
async def check(
|
46
46
|
self,
|
@@ -48,7 +48,7 @@ class CheckMixin(
|
|
48
48
|
collection: AsyncCollection | None = None,
|
49
49
|
is_migration_process: bool = False,
|
50
50
|
) -> dict[str, Any]:
|
51
|
-
"""
|
51
|
+
"""Validation of Model data before saving to the database.
|
52
52
|
|
53
53
|
It is also used to verify Models that do not migrate to the database.
|
54
54
|
"""
|
ramifice/paladins/delete.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"""
|
1
|
+
"""Delete document from database."""
|
2
2
|
|
3
3
|
__all__ = ("DeleteMixin",)
|
4
4
|
|
@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
|
|
17
17
|
|
18
18
|
|
19
19
|
class DeleteMixin:
|
20
|
-
"""
|
20
|
+
"""Delete document from database."""
|
21
21
|
|
22
22
|
async def delete(
|
23
23
|
self,
|
@@ -30,7 +30,7 @@ class DeleteMixin:
|
|
30
30
|
comment: Any | None = None,
|
31
31
|
**kwargs: dict[str, Any],
|
32
32
|
) -> dict[str, Any]:
|
33
|
-
"""
|
33
|
+
"""Delete document from database."""
|
34
34
|
cls_model = self.__class__
|
35
35
|
# Raises a panic if the Model cannot be removed.
|
36
36
|
if not cls_model.META["is_delete_doc"]:
|