ramifice 0.8.22__py3-none-any.whl → 0.8.26__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 +16 -6
- ramifice/fields/choice_float_dyn_field.py +16 -6
- ramifice/fields/choice_float_field.py +20 -8
- ramifice/fields/choice_float_mult_dyn_field.py +16 -6
- ramifice/fields/choice_float_mult_field.py +20 -8
- ramifice/fields/choice_int_dyn_field.py +16 -6
- ramifice/fields/choice_int_field.py +20 -8
- ramifice/fields/choice_int_mult_dyn_field.py +16 -6
- ramifice/fields/choice_int_mult_field.py +20 -8
- ramifice/fields/choice_text_dyn_field.py +16 -6
- ramifice/fields/choice_text_field.py +20 -8
- ramifice/fields/choice_text_mult_dyn_field.py +16 -6
- ramifice/fields/choice_text_mult_field.py +20 -8
- ramifice/fields/color_field.py +24 -11
- ramifice/fields/date_field.py +25 -10
- ramifice/fields/date_time_field.py +25 -10
- ramifice/fields/email_field.py +21 -7
- ramifice/fields/file_field.py +25 -10
- ramifice/fields/float_field.py +25 -7
- 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 +20 -15
- ramifice/fields/image_field.py +25 -9
- ramifice/fields/integer_field.py +25 -7
- ramifice/fields/ip_field.py +21 -7
- ramifice/fields/password_field.py +21 -12
- ramifice/fields/phone_field.py +22 -8
- ramifice/fields/slug_field.py +17 -6
- ramifice/fields/text_field.py +24 -7
- ramifice/fields/url_field.py +19 -19
- ramifice/models/__init__.py +7 -1
- ramifice/models/decorator.py +3 -3
- ramifice/models/model.py +16 -16
- ramifice/paladins/__init__.py +17 -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.26.dist-info}/METADATA +4 -4
- ramifice-0.8.26.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.26.dist-info}/WHEEL +0 -0
- {ramifice-0.8.22.dist-info → ramifice-0.8.26.dist-info}/licenses/LICENSE +0 -0
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,33 +17,49 @@ 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
|
+
|
28
|
+
Agrs:
|
29
|
+
label: Text label for a web form field.
|
30
|
+
placeholder: Displays prompt text.
|
31
|
+
default: Value by default.
|
32
|
+
hide: Hide field from user.
|
33
|
+
disabled: Blocks access and modification of the element.
|
34
|
+
ignored: If true, the value of this field is not saved in the database.
|
35
|
+
hint: An alternative for the `placeholder` parameter.
|
36
|
+
warning: Warning information.
|
37
|
+
required: Required field.
|
38
|
+
max_size: The maximum allowed file size in bytes.
|
39
|
+
target_dir: Directory for files inside media directory.
|
40
|
+
accept: Describing which file types to allow. Example: "image/png,image/jpeg,image/webp".
|
41
|
+
thumbnails: Sizes of thumbnails - Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }.
|
42
|
+
"""
|
27
43
|
|
28
44
|
def __init__( # noqa: D107
|
29
45
|
self,
|
30
46
|
label: str = "",
|
31
|
-
|
47
|
+
placeholder: str = "",
|
48
|
+
default: str | None = None,
|
32
49
|
hide: bool = False,
|
50
|
+
disabled: bool = False,
|
33
51
|
ignored: bool = False,
|
34
52
|
hint: str = "",
|
35
53
|
warning: list[str] | None = None,
|
36
54
|
required: bool = False,
|
37
55
|
# The maximum size of the original image in bytes.
|
38
56
|
max_size: int = 2097152, # 2 MB = 2097152 Bytes (in binary)
|
39
|
-
default: str | None = None,
|
40
|
-
placeholder: str = "",
|
41
57
|
target_dir: str = "images",
|
42
58
|
accept: str = "image/png,image/jpeg,image/webp",
|
43
59
|
# Available 4 sizes from lg to xs or None.
|
44
60
|
# Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
|
45
61
|
thumbnails: dict[str, int] | None = None,
|
46
|
-
):
|
62
|
+
) -> None:
|
47
63
|
if constants.DEBUG:
|
48
64
|
try:
|
49
65
|
if default is not None:
|
@@ -139,7 +155,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
139
155
|
filename: str | None = None,
|
140
156
|
is_delete: bool = False,
|
141
157
|
) -> None:
|
142
|
-
"""
|
158
|
+
"""Convert base64 to a image,
|
143
159
|
get image information and save in the target directory.
|
144
160
|
""" # noqa: D205
|
145
161
|
base64_str = base64_str or None
|
@@ -208,7 +224,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
208
224
|
src_path: str | None = None,
|
209
225
|
is_delete: bool = False,
|
210
226
|
) -> None:
|
211
|
-
"""
|
227
|
+
"""Get image information and copy the image to the target directory."""
|
212
228
|
src_path = src_path or None
|
213
229
|
img_info: dict[str, str | int | bool] = {"save_as_is": False}
|
214
230
|
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,24 +8,42 @@ 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
|
+
|
19
|
+
Agrs:
|
20
|
+
label: Text label for a web form field.
|
21
|
+
placeholder: Displays prompt text.
|
22
|
+
default: Value by default.
|
23
|
+
hide: Hide field from user.
|
24
|
+
disabled: Blocks access and modification of the element.
|
25
|
+
ignored: If true, the value of this field is not saved in the database.
|
26
|
+
hint: An alternative for the `placeholder` parameter.
|
27
|
+
warning: Warning information.
|
28
|
+
required: Required field.
|
29
|
+
readonly: Specifies that the field cannot be modified by the user.
|
30
|
+
unique: The unique value of a field in a collection.
|
31
|
+
max_number: Maximum allowed number.
|
32
|
+
min_number: Minimum allowed number.
|
33
|
+
step: Increment step for numeric fields.
|
34
|
+
input_type: Field type - `number` or `range`.
|
35
|
+
"""
|
18
36
|
|
19
37
|
def __init__( # noqa: D107
|
20
38
|
self,
|
21
39
|
label: str = "",
|
22
|
-
|
40
|
+
placeholder: str = "",
|
41
|
+
default: int | None = None,
|
23
42
|
hide: bool = False,
|
43
|
+
disabled: bool = False,
|
24
44
|
ignored: bool = False,
|
25
45
|
hint: str = "",
|
26
46
|
warning: list[str] | None = None,
|
27
|
-
default: int | None = None,
|
28
|
-
placeholder: str = "",
|
29
47
|
required: bool = False,
|
30
48
|
readonly: bool = False,
|
31
49
|
unique: bool = False,
|
@@ -33,7 +51,7 @@ class IntegerField(Field, NumberGroup, JsonMixin):
|
|
33
51
|
min_number: int | None = None,
|
34
52
|
step: int = 1,
|
35
53
|
input_type: Literal["number", "range"] = "number",
|
36
|
-
):
|
54
|
+
) -> None:
|
37
55
|
if constants.DEBUG:
|
38
56
|
try:
|
39
57
|
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,28 +8,42 @@ 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
|
+
|
19
|
+
Agrs:
|
20
|
+
label: Text label for a web form field.
|
21
|
+
placeholder: Displays prompt text.
|
22
|
+
default: Value by default.
|
23
|
+
hide: Hide field from user.
|
24
|
+
disabled: Blocks access and modification of the element.
|
25
|
+
ignored: If true, the value of this field is not saved in the database.
|
26
|
+
hint: An alternative for the `placeholder` parameter.
|
27
|
+
warning: Warning information.
|
28
|
+
required: Required field.
|
29
|
+
readonly: Specifies that the field cannot be modified by the user.
|
30
|
+
unique: The unique value of a field in a collection.
|
31
|
+
"""
|
18
32
|
|
19
33
|
def __init__( # noqa: D107
|
20
34
|
self,
|
21
35
|
label: str = "",
|
22
|
-
|
36
|
+
placeholder: str = "",
|
37
|
+
default: str | None = None,
|
23
38
|
hide: bool = False,
|
39
|
+
disabled: bool = False,
|
24
40
|
ignored: bool = False,
|
25
41
|
hint: str = "",
|
26
42
|
warning: list[str] | None = None,
|
27
|
-
default: str | None = None,
|
28
|
-
placeholder: str = "",
|
29
43
|
required: bool = False,
|
30
44
|
readonly: bool = False,
|
31
45
|
unique: bool = False,
|
32
|
-
):
|
46
|
+
) -> None:
|
33
47
|
if constants.DEBUG:
|
34
48
|
try:
|
35
49
|
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,24 +14,33 @@ 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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
Attention:
|
20
|
+
- Regular expression: ^[-._!"`'#%&,:;<>=@{}~$()*+/\\?[]^|a-zA-Z0-9]{8,256}$
|
21
|
+
- Valid characters: a-z A-Z 0-9 - . _ ! " ` ' # % & , : ; < > = @ { } ~ $ ( ) * + / \\ ? [ ] ^ |
|
22
|
+
- Number of characters: from 8 to 256.
|
23
|
+
|
24
|
+
Agrs:
|
25
|
+
label: Text label for a web form field.
|
26
|
+
placeholder: Displays prompt text.
|
27
|
+
hide: Hide field from user.
|
28
|
+
ignored: If true, the value of this field is not saved in the database.
|
29
|
+
hint: An alternative for the `placeholder` parameter.
|
30
|
+
warning: Warning information.
|
31
|
+
required: Required field.
|
23
32
|
"""
|
24
33
|
|
25
34
|
def __init__( # noqa: D107
|
26
35
|
self,
|
27
36
|
label: str = "",
|
37
|
+
placeholder: str = "",
|
28
38
|
hide: bool = False,
|
29
39
|
ignored: bool = False,
|
30
40
|
hint: str = "",
|
31
41
|
warning: list[str] | None = None,
|
32
|
-
placeholder: str = "",
|
33
42
|
required: bool = False,
|
34
|
-
):
|
43
|
+
) -> None:
|
35
44
|
if constants.DEBUG:
|
36
45
|
try:
|
37
46
|
if not isinstance(label, str):
|
@@ -72,7 +81,7 @@ class PasswordField(Field):
|
|
72
81
|
self.required = required
|
73
82
|
|
74
83
|
def to_dict(self) -> dict[str, Any]:
|
75
|
-
"""
|
84
|
+
"""Convert object instance to a dictionary."""
|
76
85
|
json_dict: dict[str, Any] = {}
|
77
86
|
for name, data in self.__dict__.items():
|
78
87
|
if not callable(data):
|
@@ -80,12 +89,12 @@ class PasswordField(Field):
|
|
80
89
|
return json_dict
|
81
90
|
|
82
91
|
def to_json(self) -> str:
|
83
|
-
"""
|
92
|
+
"""Convert object instance to a JSON string."""
|
84
93
|
return orjson.dumps(self.to_dict()).decode("utf-8")
|
85
94
|
|
86
95
|
@classmethod
|
87
96
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
88
|
-
"""
|
97
|
+
"""Convert JSON string to a object instance."""
|
89
98
|
obj = cls()
|
90
99
|
for name, data in json_dict.items():
|
91
100
|
obj.__dict__[name] = data
|
@@ -93,6 +102,6 @@ class PasswordField(Field):
|
|
93
102
|
|
94
103
|
@classmethod
|
95
104
|
def from_json(cls, json_str: str) -> Any:
|
96
|
-
"""
|
105
|
+
"""Convert JSON string to a object instance."""
|
97
106
|
json_dict = orjson.loads(json_str)
|
98
107
|
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,31 +9,45 @@ 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
|
+
Attention:
|
21
|
+
By default is used validator `phonenumbers.is_valid_number()`.
|
22
|
+
|
23
|
+
Agrs:
|
24
|
+
label: Text label for a web form field.
|
25
|
+
placeholder: Displays prompt text.
|
26
|
+
default: Value by default.
|
27
|
+
hide: Hide field from user.
|
28
|
+
disabled: Blocks access and modification of the element.
|
29
|
+
ignored: If true, the value of this field is not saved in the database.
|
30
|
+
hint: An alternative for the `placeholder` parameter.
|
31
|
+
warning: Warning information.
|
32
|
+
required: Required field.
|
33
|
+
readonly: Specifies that the field cannot be modified by the user.
|
34
|
+
unique: The unique value of a field in a collection.
|
21
35
|
"""
|
22
36
|
|
23
37
|
def __init__( # noqa: D107
|
24
38
|
self,
|
25
39
|
label: str = "",
|
26
|
-
|
40
|
+
placeholder: str = "",
|
41
|
+
default: str | None = None,
|
27
42
|
hide: bool = False,
|
43
|
+
disabled: bool = False,
|
28
44
|
ignored: bool = False,
|
29
45
|
hint: str = "",
|
30
46
|
warning: list[str] | None = None,
|
31
|
-
default: str | None = None,
|
32
|
-
placeholder: str = "",
|
33
47
|
required: bool = False,
|
34
48
|
readonly: bool = False,
|
35
49
|
unique: bool = False,
|
36
|
-
):
|
50
|
+
) -> None:
|
37
51
|
if constants.DEBUG:
|
38
52
|
try:
|
39
53
|
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,29 +7,40 @@ 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
|
+
|
20
|
+
Agrs:
|
21
|
+
label: Text label for a web form field.
|
22
|
+
placeholder: Displays prompt text.
|
23
|
+
hide: Hide field from user.
|
24
|
+
disabled: Blocks access and modification of the element.
|
25
|
+
ignored: If true, the value of this field is not saved in the database.
|
26
|
+
hint: An alternative for the `placeholder` parameter.
|
27
|
+
warning: Warning information.
|
28
|
+
readonly: Specifies that the field cannot be modified by the user.
|
29
|
+
slug_sources: List of sources fields.
|
19
30
|
"""
|
20
31
|
|
21
32
|
def __init__( # noqa: D107
|
22
33
|
self,
|
23
34
|
label: str = "",
|
24
|
-
|
35
|
+
placeholder: str = "",
|
25
36
|
hide: bool = False,
|
37
|
+
disabled: bool = False,
|
26
38
|
ignored: bool = False,
|
27
39
|
hint: str = "",
|
28
40
|
warning: list[str] | None = None,
|
29
|
-
placeholder: str = "",
|
30
41
|
readonly: bool = False,
|
31
42
|
slug_sources: list[str] = ["_id"],
|
32
|
-
):
|
43
|
+
) -> None:
|
33
44
|
if constants.DEBUG:
|
34
45
|
try:
|
35
46
|
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,32 +6,49 @@ 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
|
+
|
17
|
+
Agrs:
|
18
|
+
label: Text label for a web form field.
|
19
|
+
placeholder: Displays prompt text.
|
20
|
+
hide: Hide field from user.
|
21
|
+
disabled: Blocks access and modification of the element.
|
22
|
+
ignored: If true, the value of this field is not saved in the database.
|
23
|
+
hint: An alternative for the `placeholder` parameter.
|
24
|
+
warning: Warning information.
|
25
|
+
textarea: Is it necessary to use the Textarea widget.
|
26
|
+
use_editor: Is it necessary to use the widget of the text editor.
|
27
|
+
required: Required field.
|
28
|
+
readonly: Specifies that the field cannot be modified by the user.
|
29
|
+
unique: The unique value of a field in a collection.
|
30
|
+
maxlength: The maximum line length.
|
31
|
+
multi_language: Is it need support for several languages.
|
32
|
+
"""
|
16
33
|
|
17
34
|
def __init__( # noqa: D107
|
18
35
|
self,
|
19
36
|
label: str = "",
|
20
|
-
|
37
|
+
placeholder: str = "",
|
21
38
|
hide: bool = False,
|
39
|
+
disabled: bool = False,
|
22
40
|
ignored: bool = False,
|
23
41
|
hint: str = "",
|
24
42
|
warning: list[str] | None = None,
|
25
43
|
textarea: bool = False,
|
26
44
|
use_editor: bool = False,
|
27
|
-
placeholder: str = "",
|
28
45
|
required: bool = False,
|
29
46
|
readonly: bool = False,
|
30
47
|
unique: bool = False,
|
31
48
|
maxlength: int = 256,
|
32
49
|
# Support for several language.
|
33
50
|
multi_language: bool = False,
|
34
|
-
):
|
51
|
+
) -> None:
|
35
52
|
if constants.DEBUG:
|
36
53
|
try:
|
37
54
|
if not isinstance(maxlength, int):
|
@@ -96,7 +113,7 @@ class TextField(Field, JsonMixin):
|
|
96
113
|
self.multi_language = multi_language
|
97
114
|
|
98
115
|
def __len__(self) -> int:
|
99
|
-
"""
|
116
|
+
"""Return length of field `value`."""
|
100
117
|
value = self.value
|
101
118
|
if isinstance(value, str):
|
102
119
|
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,42 +8,42 @@ 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
|
-
|
20
|
-
label
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
required
|
29
|
-
readonly
|
30
|
-
unique
|
19
|
+
Agrs:
|
20
|
+
label: Text label for a web form field.
|
21
|
+
placeholder: Displays prompt text.
|
22
|
+
default: Value by default.
|
23
|
+
hide: Hide field from user.
|
24
|
+
disabled: Blocks access and modification of the element.
|
25
|
+
ignored: If true, the value of this field is not saved in the database.
|
26
|
+
hint: An alternative for the `placeholder` parameter.
|
27
|
+
warning: Warning information.
|
28
|
+
required: Required field.
|
29
|
+
readonly: Specifies that the field cannot be modified by the user.
|
30
|
+
unique: The unique value of a field in a collection.
|
31
31
|
"""
|
32
32
|
|
33
33
|
def __init__( # noqa: D107
|
34
34
|
self,
|
35
35
|
label: str = "",
|
36
|
-
|
36
|
+
placeholder: str = "",
|
37
|
+
default: str | None = None,
|
37
38
|
hide: bool = False,
|
39
|
+
disabled: bool = False,
|
38
40
|
ignored: bool = False,
|
39
41
|
hint: str = "",
|
40
42
|
warning: list[str] | None = None,
|
41
|
-
default: str | None = None,
|
42
|
-
placeholder: str = "",
|
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
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
|