ramifice 0.8.26__py3-none-any.whl → 0.8.28__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/commons/many.py +4 -8
- ramifice/commons/one.py +1 -3
- ramifice/commons/tools.py +1 -5
- ramifice/commons/unit_manager.py +2 -4
- ramifice/fields/choice_float_field.py +2 -5
- ramifice/fields/choice_float_mult_field.py +3 -8
- ramifice/fields/choice_int_field.py +2 -5
- ramifice/fields/choice_int_mult_field.py +3 -8
- ramifice/fields/choice_text_field.py +3 -8
- ramifice/fields/choice_text_mult_field.py +3 -8
- ramifice/fields/color_field.py +1 -3
- ramifice/fields/date_field.py +1 -3
- ramifice/fields/date_time_field.py +1 -3
- ramifice/fields/email_field.py +2 -4
- ramifice/fields/file_field.py +4 -6
- ramifice/fields/float_field.py +3 -5
- ramifice/fields/general/choice_group.py +1 -3
- ramifice/fields/general/date_group.py +1 -2
- ramifice/fields/general/field.py +2 -4
- ramifice/fields/general/file_group.py +1 -3
- ramifice/fields/general/number_group.py +1 -3
- ramifice/fields/general/text_group.py +1 -3
- ramifice/fields/image_field.py +6 -12
- ramifice/fields/integer_field.py +3 -5
- ramifice/fields/ip_field.py +2 -4
- ramifice/fields/phone_field.py +2 -4
- ramifice/fields/slug_field.py +1 -1
- ramifice/fields/url_field.py +1 -3
- ramifice/models/decorator.py +3 -5
- ramifice/models/model.py +5 -7
- ramifice/paladins/add_valid.py +3 -2
- ramifice/paladins/check.py +6 -8
- ramifice/paladins/groups/date_group.py +1 -3
- ramifice/paladins/groups/file_group.py +1 -3
- ramifice/paladins/groups/img_group.py +1 -3
- ramifice/paladins/groups/num_group.py +2 -6
- ramifice/paladins/groups/slug_group.py +1 -1
- ramifice/paladins/groups/text_group.py +2 -2
- ramifice/paladins/hooks.py +8 -2
- ramifice/paladins/indexing.py +3 -2
- ramifice/paladins/save.py +4 -10
- ramifice/paladins/validation.py +9 -9
- ramifice/utils/constants.py +1 -1
- ramifice/utils/fixtures.py +4 -4
- ramifice/utils/migration.py +10 -21
- ramifice/utils/tools.py +1 -1
- ramifice/utils/translations.py +1 -1
- ramifice/utils/unit.py +3 -6
- {ramifice-0.8.26.dist-info → ramifice-0.8.28.dist-info}/METADATA +2 -1
- ramifice-0.8.28.dist-info/RECORD +83 -0
- ramifice-0.8.26.dist-info/RECORD +0 -83
- {ramifice-0.8.26.dist-info → ramifice-0.8.28.dist-info}/WHEEL +0 -0
- {ramifice-0.8.26.dist-info → ramifice-0.8.28.dist-info}/licenses/LICENSE +0 -0
ramifice/commons/many.py
CHANGED
@@ -148,9 +148,7 @@ class ManyMixin:
|
|
148
148
|
session=session,
|
149
149
|
allow_disk_use=allow_disk_use,
|
150
150
|
)
|
151
|
-
inst_model_dict = {
|
152
|
-
key: val for key, val in cls().__dict__.items() if not callable(val) and not val.ignored
|
153
|
-
}
|
151
|
+
inst_model_dict = {key: val for key, val in cls().__dict__.items() if not callable(val) and not val.ignored}
|
154
152
|
lang = translations.CURRENT_LOCALE
|
155
153
|
async for mongo_doc in cursor:
|
156
154
|
doc_list.append(
|
@@ -158,7 +156,7 @@ class ManyMixin:
|
|
158
156
|
inst_model_dict,
|
159
157
|
mongo_doc,
|
160
158
|
lang,
|
161
|
-
)
|
159
|
+
),
|
162
160
|
)
|
163
161
|
return doc_list
|
164
162
|
|
@@ -218,9 +216,7 @@ class ManyMixin:
|
|
218
216
|
session=session,
|
219
217
|
allow_disk_use=allow_disk_use,
|
220
218
|
)
|
221
|
-
inst_model_dict = {
|
222
|
-
key: val for key, val in cls().__dict__.items() if not callable(val) and not val.ignored
|
223
|
-
}
|
219
|
+
inst_model_dict = {key: val for key, val in cls().__dict__.items() if not callable(val) and not val.ignored}
|
224
220
|
lang = translations.CURRENT_LOCALE
|
225
221
|
async for mongo_doc in cursor:
|
226
222
|
doc_list.append(
|
@@ -228,7 +224,7 @@ class ManyMixin:
|
|
228
224
|
inst_model_dict,
|
229
225
|
mongo_doc,
|
230
226
|
lang,
|
231
|
-
)
|
227
|
+
),
|
232
228
|
)
|
233
229
|
return orjson.dumps(doc_list).decode("utf-8") if len(doc_list) > 0 else None
|
234
230
|
|
ramifice/commons/one.py
CHANGED
@@ -60,9 +60,7 @@ class OneMixin:
|
|
60
60
|
# Get document.
|
61
61
|
raw_doc = None
|
62
62
|
mongo_doc = await collection.find_one(filter, *args, **kwargs)
|
63
|
-
inst_model_dict = {
|
64
|
-
key: val for key, val in cls().__dict__.items() if not callable(val) and not val.ignored
|
65
|
-
}
|
63
|
+
inst_model_dict = {key: val for key, val in cls().__dict__.items() if not callable(val) and not val.ignored}
|
66
64
|
if mongo_doc is not None:
|
67
65
|
raw_doc = mongo_doc_to_raw_doc(
|
68
66
|
inst_model_dict,
|
ramifice/commons/tools.py
CHANGED
@@ -21,11 +21,7 @@ def correct_mongo_filter(cls_model: Any, filter: Any) -> Any:
|
|
21
21
|
"""
|
22
22
|
lang: str = translations.CURRENT_LOCALE
|
23
23
|
filter_json: str = json_util.dumps(filter)
|
24
|
-
filter_json = (
|
25
|
-
cls_model.META["regex_mongo_filter"]
|
26
|
-
.sub(rf'\g<field>.{lang}":', filter_json)
|
27
|
-
.replace('":.', ".")
|
28
|
-
)
|
24
|
+
filter_json = cls_model.META["regex_mongo_filter"].sub(rf'\g<field>.{lang}":', filter_json).replace('":.', ".")
|
29
25
|
return json_util.loads(filter_json)
|
30
26
|
|
31
27
|
|
ramifice/commons/unit_manager.py
CHANGED
@@ -35,12 +35,10 @@ class UnitMixin:
|
|
35
35
|
"""
|
36
36
|
# Get access to super collection.
|
37
37
|
# (Contains Model state and dynamic field data.)
|
38
|
-
super_collection: AsyncCollection = constants.MONGO_DATABASE[
|
39
|
-
constants.SUPER_COLLECTION_NAME
|
40
|
-
]
|
38
|
+
super_collection: AsyncCollection = constants.MONGO_DATABASE[constants.SUPER_COLLECTION_NAME]
|
41
39
|
# Get Model state.
|
42
40
|
model_state: dict[str, Any] | None = await super_collection.find_one(
|
43
|
-
filter={"collection_name": cls.META["collection_name"]}
|
41
|
+
filter={"collection_name": cls.META["collection_name"]},
|
44
42
|
)
|
45
43
|
# Check the presence of a Model state.
|
46
44
|
if model_state is None:
|
@@ -75,15 +75,12 @@ class ChoiceFloatField(Field, ChoiceGroup, JsonMixin):
|
|
75
75
|
if not isinstance(choices, list):
|
76
76
|
raise AssertionError("Parameter `choices` - Not а `list` type!")
|
77
77
|
if len(choices) == 0:
|
78
|
-
raise AssertionError(
|
79
|
-
"The `choices` parameter should not contain an empty list!"
|
80
|
-
)
|
78
|
+
raise AssertionError("The `choices` parameter should not contain an empty list!")
|
81
79
|
if default is not None and not isinstance(default, float):
|
82
80
|
raise AssertionError("Parameter `default` - Not а `float` type!")
|
83
81
|
if default is not None and choices is not None and not self.has_value():
|
84
82
|
raise AssertionError(
|
85
|
-
"Parameter `default` does not coincide with "
|
86
|
-
+ "list of permissive values in `choicees`."
|
83
|
+
"Parameter `default` does not coincide with " + "list of permissive values in `choicees`.",
|
87
84
|
)
|
88
85
|
if not isinstance(label, str):
|
89
86
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -76,20 +76,15 @@ class ChoiceFloatMultField(Field, ChoiceGroup, JsonMixin):
|
|
76
76
|
if not isinstance(choices, list):
|
77
77
|
raise AssertionError("Parameter `choices` - Not а `list` type!")
|
78
78
|
if len(choices) == 0:
|
79
|
-
raise AssertionError(
|
80
|
-
"The `choices` parameter should not contain an empty list!"
|
81
|
-
)
|
79
|
+
raise AssertionError("The `choices` parameter should not contain an empty list!")
|
82
80
|
if default is not None:
|
83
81
|
if not isinstance(default, list):
|
84
82
|
raise AssertionError("Parameter `default` - Not а `list` type!")
|
85
83
|
if len(default) == 0:
|
86
|
-
raise AssertionError(
|
87
|
-
"The `default` parameter should not contain an empty list!"
|
88
|
-
)
|
84
|
+
raise AssertionError("The `default` parameter should not contain an empty list!")
|
89
85
|
if choices is not None and not self.has_value():
|
90
86
|
raise AssertionError(
|
91
|
-
"Parameter `default` does not coincide with "
|
92
|
-
+ "list of permissive values in `choicees`."
|
87
|
+
"Parameter `default` does not coincide with " + "list of permissive values in `choicees`.",
|
93
88
|
)
|
94
89
|
if not isinstance(label, str):
|
95
90
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -75,15 +75,12 @@ class ChoiceIntField(Field, ChoiceGroup, JsonMixin):
|
|
75
75
|
if not isinstance(choices, list):
|
76
76
|
raise AssertionError("Parameter `choices` - Not а `list` type!")
|
77
77
|
if len(choices) == 0:
|
78
|
-
raise AssertionError(
|
79
|
-
"The `choices` parameter should not contain an empty list!"
|
80
|
-
)
|
78
|
+
raise AssertionError("The `choices` parameter should not contain an empty list!")
|
81
79
|
if default is not None and not isinstance(default, int):
|
82
80
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
83
81
|
if default is not None and choices is not None and not self.has_value():
|
84
82
|
raise AssertionError(
|
85
|
-
"Parameter `default` does not coincide with "
|
86
|
-
+ "list of permissive values in `choicees`."
|
83
|
+
"Parameter `default` does not coincide with " + "list of permissive values in `choicees`.",
|
87
84
|
)
|
88
85
|
if not isinstance(label, str):
|
89
86
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -76,20 +76,15 @@ class ChoiceIntMultField(Field, ChoiceGroup, JsonMixin):
|
|
76
76
|
if not isinstance(choices, list):
|
77
77
|
raise AssertionError("Parameter `choices` - Not а `list` type!")
|
78
78
|
if len(choices) == 0:
|
79
|
-
raise AssertionError(
|
80
|
-
"The `choices` parameter should not contain an empty list!"
|
81
|
-
)
|
79
|
+
raise AssertionError("The `choices` parameter should not contain an empty list!")
|
82
80
|
if default is not None:
|
83
81
|
if not isinstance(default, list):
|
84
82
|
raise AssertionError("Parameter `default` - Not а `list` type!")
|
85
83
|
if len(default) == 0:
|
86
|
-
raise AssertionError(
|
87
|
-
"The `default` parameter should not contain an empty list!"
|
88
|
-
)
|
84
|
+
raise AssertionError("The `default` parameter should not contain an empty list!")
|
89
85
|
if choices is not None and not self.has_value():
|
90
86
|
raise AssertionError(
|
91
|
-
"Parameter `default` does not coincide with "
|
92
|
-
+ "list of permissive values in `choicees`."
|
87
|
+
"Parameter `default` does not coincide with " + "list of permissive values in `choicees`.",
|
93
88
|
)
|
94
89
|
if not isinstance(label, str):
|
95
90
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -75,20 +75,15 @@ class ChoiceTextField(Field, ChoiceGroup, JsonMixin):
|
|
75
75
|
if not isinstance(choices, list):
|
76
76
|
raise AssertionError("Parameter `choices` - Not а `list` type!")
|
77
77
|
if len(choices) == 0:
|
78
|
-
raise AssertionError(
|
79
|
-
"The `choices` parameter should not contain an empty list!"
|
80
|
-
)
|
78
|
+
raise AssertionError("The `choices` parameter should not contain an empty list!")
|
81
79
|
if default is not None:
|
82
80
|
if not isinstance(default, str):
|
83
81
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
84
82
|
if len(default) == 0:
|
85
|
-
raise AssertionError(
|
86
|
-
"The `default` parameter should not contain an empty string!"
|
87
|
-
)
|
83
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
88
84
|
if choices is not None and not self.has_value():
|
89
85
|
raise AssertionError(
|
90
|
-
"Parameter `default` does not coincide with "
|
91
|
-
+ "list of permissive values in `choicees`."
|
86
|
+
"Parameter `default` does not coincide with " + "list of permissive values in `choicees`.",
|
92
87
|
)
|
93
88
|
if not isinstance(label, str):
|
94
89
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -76,20 +76,15 @@ class ChoiceTextMultField(Field, ChoiceGroup, JsonMixin):
|
|
76
76
|
if not isinstance(choices, list):
|
77
77
|
raise AssertionError("Parameter `choices` - Not а `list` type!")
|
78
78
|
if len(choices) == 0:
|
79
|
-
raise AssertionError(
|
80
|
-
"The `choices` parameter should not contain an empty list!"
|
81
|
-
)
|
79
|
+
raise AssertionError("The `choices` parameter should not contain an empty list!")
|
82
80
|
if default is not None:
|
83
81
|
if not isinstance(default, list):
|
84
82
|
raise AssertionError("Parameter `default` - Not а `list` type!")
|
85
83
|
if len(default) == 0:
|
86
|
-
raise AssertionError(
|
87
|
-
"The `default` parameter should not contain an empty list!"
|
88
|
-
)
|
84
|
+
raise AssertionError("The `default` parameter should not contain an empty list!")
|
89
85
|
if choices is not None and not self.has_value():
|
90
86
|
raise AssertionError(
|
91
|
-
"Parameter `default` does not coincide with "
|
92
|
-
+ "list of permissive values in `choicees`."
|
87
|
+
"Parameter `default` does not coincide with " + "list of permissive values in `choicees`.",
|
93
88
|
)
|
94
89
|
if not isinstance(label, str):
|
95
90
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/color_field.py
CHANGED
@@ -56,9 +56,7 @@ class ColorField(Field, TextGroup, JsonMixin):
|
|
56
56
|
if not isinstance(default, str):
|
57
57
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
58
58
|
if len(default) == 0:
|
59
|
-
raise AssertionError(
|
60
|
-
"The `default` parameter should not contain an empty string!"
|
61
|
-
)
|
59
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
62
60
|
if constants.REGEX["color_code"].match(default) is None:
|
63
61
|
raise AssertionError("Parameter `default` - Not а color code!")
|
64
62
|
if not isinstance(label, str):
|
ramifice/fields/date_field.py
CHANGED
@@ -59,9 +59,7 @@ class DateField(Field, DateGroup):
|
|
59
59
|
if not isinstance(min_date, datetime):
|
60
60
|
raise AssertionError("Parameter `min_date` - Not а `str` type!")
|
61
61
|
if max_date is not None and min_date is not None and max_date <= min_date:
|
62
|
-
raise AssertionError(
|
63
|
-
"The `max_date` parameter should be more than the `min_date`!"
|
64
|
-
)
|
62
|
+
raise AssertionError("The `max_date` parameter should be more than the `min_date`!")
|
65
63
|
if default is not None:
|
66
64
|
if not isinstance(default, datetime):
|
67
65
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -59,9 +59,7 @@ class DateTimeField(Field, DateGroup):
|
|
59
59
|
if not isinstance(min_date, datetime):
|
60
60
|
raise AssertionError("Parameter `min_date` - Not а `str` type!")
|
61
61
|
if max_date is not None and min_date is not None and max_date <= min_date:
|
62
|
-
raise AssertionError(
|
63
|
-
"The `max_date` parameter should be more than the `min_date`!"
|
64
|
-
)
|
62
|
+
raise AssertionError("The `max_date` parameter should be more than the `min_date`!")
|
65
63
|
if default is not None:
|
66
64
|
if not isinstance(default, datetime):
|
67
65
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/email_field.py
CHANGED
@@ -51,13 +51,11 @@ class EmailField(Field, TextGroup, JsonMixin):
|
|
51
51
|
if not isinstance(default, str):
|
52
52
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
53
53
|
if len(default) == 0:
|
54
|
-
raise AssertionError(
|
55
|
-
"The `default` parameter should not contain an empty string!"
|
56
|
-
)
|
54
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
57
55
|
try:
|
58
56
|
validate_email(default, check_deliverability=True)
|
59
57
|
except EmailNotValidError:
|
60
|
-
raise AssertionError("Parameter `default` - Invalid Email address!")
|
58
|
+
raise AssertionError("Parameter `default` - Invalid Email address!") # noqa: B904
|
61
59
|
if not isinstance(label, str):
|
62
60
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
63
61
|
if not isinstance(disabled, bool):
|
ramifice/fields/file_field.py
CHANGED
@@ -5,7 +5,7 @@ __all__ = ("FileField",)
|
|
5
5
|
import logging
|
6
6
|
import uuid
|
7
7
|
from base64 import b64decode
|
8
|
-
from datetime import
|
8
|
+
from datetime import datetime
|
9
9
|
from os import makedirs
|
10
10
|
from os.path import basename, exists, getsize
|
11
11
|
from shutil import copyfile
|
@@ -62,9 +62,7 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
62
62
|
if not isinstance(default, str):
|
63
63
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
64
64
|
if len(default) == 0:
|
65
|
-
raise AssertionError(
|
66
|
-
"The `default` parameter should not contain an empty string!"
|
67
|
-
)
|
65
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
68
66
|
if not isinstance(label, str):
|
69
67
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
70
68
|
if not isinstance(disabled, bool):
|
@@ -149,7 +147,7 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
149
147
|
# Create new (uuid) file name.
|
150
148
|
f_uuid_name = f"{uuid.uuid4()}{extension}"
|
151
149
|
# Create the current date for the directory name.
|
152
|
-
date_str: str = str(
|
150
|
+
date_str: str = str(datetime.now().date()) # noqa: DTZ005
|
153
151
|
# Create path to target directory.
|
154
152
|
dir_target_path = f"{MEDIA_ROOT}/uploads/{self.target_dir}/{date_str}"
|
155
153
|
# Create target directory if it does not exist.
|
@@ -195,7 +193,7 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
195
193
|
# Create new (uuid) file name.
|
196
194
|
f_uuid_name = f"{uuid.uuid4()}{extension}"
|
197
195
|
# Create the current date for the directory name.
|
198
|
-
date_str: str = str(
|
196
|
+
date_str: str = str(datetime.now().date()) # noqa: DTZ005
|
199
197
|
# Create path to target directory.
|
200
198
|
dir_target_path = f"{MEDIA_ROOT}/uploads/{self.target_dir}/{date_str}"
|
201
199
|
# Create target directory if it does not exist.
|
ramifice/fields/float_field.py
CHANGED
@@ -57,7 +57,7 @@ class FloatField(Field, NumberGroup, JsonMixin):
|
|
57
57
|
if input_type not in ["number", "range"]:
|
58
58
|
raise AssertionError(
|
59
59
|
"Parameter `input_type` - Invalid input type! "
|
60
|
-
+ "The permissible value of `number` or `range`."
|
60
|
+
+ "The permissible value of `number` or `range`.",
|
61
61
|
)
|
62
62
|
if max_number is not None and not isinstance(max_number, float):
|
63
63
|
raise AssertionError("Parameter `max_number` - Not а number `float` type!")
|
@@ -66,15 +66,13 @@ class FloatField(Field, NumberGroup, JsonMixin):
|
|
66
66
|
if not isinstance(step, float):
|
67
67
|
raise AssertionError("Parameter `step` - Not а number `float` type!")
|
68
68
|
if max_number is not None and min_number is not None and max_number <= min_number:
|
69
|
-
raise AssertionError(
|
70
|
-
"The `max_number` parameter should be more than the `min_number`!"
|
71
|
-
)
|
69
|
+
raise AssertionError("The `max_number` parameter should be more than the `min_number`!")
|
72
70
|
if default is not None:
|
73
71
|
if not isinstance(default, float):
|
74
72
|
raise AssertionError("Parameter `default` - Not а number `float` type!")
|
75
73
|
if max_number is not None and default > max_number:
|
76
74
|
raise AssertionError("Parameter `default` is more `max_number`!")
|
77
|
-
if max_number is not None and default < min_number:
|
75
|
+
if max_number is not None and default < min_number:
|
78
76
|
raise AssertionError("Parameter `default` is less `min_number`!")
|
79
77
|
if not isinstance(label, str):
|
80
78
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/general/field.py
CHANGED
@@ -2,10 +2,8 @@
|
|
2
2
|
|
3
3
|
__all__ = ("Field",)
|
4
4
|
|
5
|
-
from abc import ABCMeta
|
6
5
|
|
7
|
-
|
8
|
-
class Field(metaclass=ABCMeta):
|
6
|
+
class Field:
|
9
7
|
"""General parameters for all types fields of Model.
|
10
8
|
|
11
9
|
Args:
|
@@ -28,7 +26,7 @@ class Field(metaclass=ABCMeta):
|
|
28
26
|
ignored: bool = False,
|
29
27
|
hint: str = "",
|
30
28
|
warning: list[str] | None = None,
|
31
|
-
errors: list[str] = [],
|
29
|
+
errors: list[str] = [], # noqa: B006
|
32
30
|
field_type: str = "",
|
33
31
|
group: str = "",
|
34
32
|
) -> None:
|
ramifice/fields/image_field.py
CHANGED
@@ -5,7 +5,7 @@ __all__ = ("ImageField",)
|
|
5
5
|
import logging
|
6
6
|
import uuid
|
7
7
|
from base64 import b64decode
|
8
|
-
from datetime import
|
8
|
+
from datetime import datetime
|
9
9
|
from os import makedirs
|
10
10
|
from os.path import basename, exists, getsize
|
11
11
|
from shutil import copyfile
|
@@ -57,7 +57,6 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
57
57
|
target_dir: str = "images",
|
58
58
|
accept: str = "image/png,image/jpeg,image/webp",
|
59
59
|
# Available 4 sizes from lg to xs or None.
|
60
|
-
# Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
|
61
60
|
thumbnails: dict[str, int] | None = None,
|
62
61
|
) -> None:
|
63
62
|
if constants.DEBUG:
|
@@ -66,16 +65,12 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
66
65
|
if not isinstance(default, str):
|
67
66
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
68
67
|
if len(default) == 0:
|
69
|
-
raise AssertionError(
|
70
|
-
"The `default` parameter should not contain an empty string!"
|
71
|
-
)
|
68
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
72
69
|
if thumbnails is not None:
|
73
70
|
if not isinstance(thumbnails, dict):
|
74
71
|
raise AssertionError("Parameter `thumbnails` - Not а `dict` type!")
|
75
72
|
if len(thumbnails) == 0:
|
76
|
-
raise AssertionError(
|
77
|
-
"The `thumbnails` parameter should not contain an empty dictionary!"
|
78
|
-
)
|
73
|
+
raise AssertionError("The `thumbnails` parameter should not contain an empty dictionary!")
|
79
74
|
size_name_list = ["lg", "md", "sm", "xs"]
|
80
75
|
curr_size_thumb: int = 0
|
81
76
|
for size_name in thumbnails.keys():
|
@@ -91,7 +86,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
91
86
|
raise AssertionError(
|
92
87
|
"The `thumbnails` parameter -> "
|
93
88
|
+ f"The `{size_name}` key should be less than a previous size!"
|
94
|
-
+ 'Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }'
|
89
|
+
+ 'Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }',
|
95
90
|
)
|
96
91
|
curr_size_thumb = max_size_thumb
|
97
92
|
if not isinstance(label, str):
|
@@ -146,7 +141,6 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
146
141
|
|
147
142
|
self.value: dict[str, str | int | bool] | None = None
|
148
143
|
# Available 4 sizes from lg to xs or None.
|
149
|
-
# Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
|
150
144
|
self.thumbnails = thumbnails
|
151
145
|
|
152
146
|
async def from_base64(
|
@@ -179,7 +173,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
179
173
|
if item[0] == 40:
|
180
174
|
break
|
181
175
|
# Create the current date for the directory name.
|
182
|
-
date_str: str = str(
|
176
|
+
date_str: str = str(datetime.now().date()) # noqa: DTZ005
|
183
177
|
# Directory name for the original image and its thumbnails.
|
184
178
|
general_dir = uuid.uuid4()
|
185
179
|
# Create path to target directory with images.
|
@@ -238,7 +232,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
238
232
|
logger.error(msg)
|
239
233
|
raise FileHasNoExtensionError(msg)
|
240
234
|
# Create the current date for the directory name.
|
241
|
-
date_str: str = str(
|
235
|
+
date_str: str = str(datetime.now().date()) # noqa: DTZ005
|
242
236
|
# Directory name for the original image and its thumbnails.
|
243
237
|
general_dir = uuid.uuid4()
|
244
238
|
# Create path to target directory with images.
|
ramifice/fields/integer_field.py
CHANGED
@@ -57,7 +57,7 @@ class IntegerField(Field, NumberGroup, JsonMixin):
|
|
57
57
|
if input_type not in ["number", "range"]:
|
58
58
|
raise AssertionError(
|
59
59
|
"Parameter `input_type` - Invalid input type! "
|
60
|
-
+ "The permissible value of `number` or `range`."
|
60
|
+
+ "The permissible value of `number` or `range`.",
|
61
61
|
)
|
62
62
|
if max_number is not None and not isinstance(max_number, int):
|
63
63
|
raise AssertionError("Parameter `max_number` - Not а number `int` type!")
|
@@ -66,15 +66,13 @@ class IntegerField(Field, NumberGroup, JsonMixin):
|
|
66
66
|
if not isinstance(step, int):
|
67
67
|
raise AssertionError("Parameter `step` - Not а number `int` type!")
|
68
68
|
if max_number is not None and min_number is not None and max_number <= min_number:
|
69
|
-
raise AssertionError(
|
70
|
-
"The `max_number` parameter should be more than the `min_number`!"
|
71
|
-
)
|
69
|
+
raise AssertionError("The `max_number` parameter should be more than the `min_number`!")
|
72
70
|
if default is not None:
|
73
71
|
if not isinstance(default, int):
|
74
72
|
raise AssertionError("Parameter `default` - Not а number `int` type!")
|
75
73
|
if max_number is not None and default > max_number:
|
76
74
|
raise AssertionError("Parameter `default` is more `max_number`!")
|
77
|
-
if max_number is not None and default < min_number:
|
75
|
+
if max_number is not None and default < min_number:
|
78
76
|
raise AssertionError("Parameter `default` is less `min_number`!")
|
79
77
|
if not isinstance(label, str):
|
80
78
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/ip_field.py
CHANGED
@@ -50,13 +50,11 @@ class IPField(Field, TextGroup, JsonMixin):
|
|
50
50
|
if not isinstance(default, str):
|
51
51
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
52
52
|
if len(default) == 0:
|
53
|
-
raise AssertionError(
|
54
|
-
"The `default` parameter should not contain an empty string!"
|
55
|
-
)
|
53
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
56
54
|
try:
|
57
55
|
ipaddress.ip_address(default)
|
58
56
|
except ValueError:
|
59
|
-
raise AssertionError("Parameter `default` - Invalid IP address!")
|
57
|
+
raise AssertionError("Parameter `default` - Invalid IP address!") # noqa: B904
|
60
58
|
if not isinstance(label, str):
|
61
59
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
62
60
|
if not isinstance(disabled, bool):
|
ramifice/fields/phone_field.py
CHANGED
@@ -54,15 +54,13 @@ class PhoneField(Field, TextGroup, JsonMixin):
|
|
54
54
|
if not isinstance(default, str):
|
55
55
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
56
56
|
if len(default) == 0:
|
57
|
-
raise AssertionError(
|
58
|
-
"The `default` parameter should not contain an empty string!"
|
59
|
-
)
|
57
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
60
58
|
try:
|
61
59
|
phone_default = phonenumbers.parse(default)
|
62
60
|
if not phonenumbers.is_valid_number(phone_default):
|
63
61
|
raise AssertionError()
|
64
62
|
except phonenumbers.phonenumberutil.NumberParseException:
|
65
|
-
raise AssertionError("Parameter `default` - Invalid Phone number!")
|
63
|
+
raise AssertionError("Parameter `default` - Invalid Phone number!") # noqa: B904
|
66
64
|
if not isinstance(label, str):
|
67
65
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
68
66
|
if not isinstance(disabled, bool):
|
ramifice/fields/slug_field.py
CHANGED
@@ -39,7 +39,7 @@ class SlugField(Field, TextGroup, JsonMixin):
|
|
39
39
|
hint: str = "",
|
40
40
|
warning: list[str] | None = None,
|
41
41
|
readonly: bool = False,
|
42
|
-
slug_sources: list[str] = ["_id"],
|
42
|
+
slug_sources: list[str] = ["_id"], # noqa: B006
|
43
43
|
) -> None:
|
44
44
|
if constants.DEBUG:
|
45
45
|
try:
|
ramifice/fields/url_field.py
CHANGED
@@ -50,9 +50,7 @@ class URLField(Field, TextGroup, JsonMixin):
|
|
50
50
|
if not isinstance(default, str):
|
51
51
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
52
52
|
if len(default) == 0:
|
53
|
-
raise AssertionError(
|
54
|
-
"The `default` parameter should not contain an empty string!"
|
55
|
-
)
|
53
|
+
raise AssertionError("The `default` parameter should not contain an empty string!")
|
56
54
|
result = urlparse(default)
|
57
55
|
if not result.scheme or not result.netloc:
|
58
56
|
raise AssertionError("Parameter `default` - Invalid URL address!")
|
ramifice/models/decorator.py
CHANGED
@@ -61,13 +61,13 @@ def model(
|
|
61
61
|
if not exists(fixture_path):
|
62
62
|
msg = (
|
63
63
|
f"Model: `{cls.__module__}.{cls.__name__}` > "
|
64
|
-
+
|
64
|
+
+ "META param: `fixture_name` => "
|
65
65
|
+ f"Fixture the `{fixture_path}` not exists!"
|
66
66
|
)
|
67
67
|
logger.critical(msg)
|
68
68
|
raise PanicError(msg)
|
69
69
|
|
70
|
-
attrs =
|
70
|
+
attrs = dict(cls.__dict__)
|
71
71
|
attrs["__dict__"] = Model.__dict__["__dict__"]
|
72
72
|
metadata = {
|
73
73
|
"service_name": service_name,
|
@@ -158,8 +158,6 @@ def caching(cls: Any, service_name: str) -> dict[str, Any]:
|
|
158
158
|
metadata["data_dynamic_fields"] = data_dynamic_fields
|
159
159
|
metadata["count_all_fields"] = count_all_fields
|
160
160
|
metadata["count_fields_no_ignored"] = count_fields_no_ignored
|
161
|
-
metadata["regex_mongo_filter"] = re.compile(
|
162
|
-
rf'(?P<field>"(?:{"|".join(supported_lang_fields)})":)'
|
163
|
-
)
|
161
|
+
metadata["regex_mongo_filter"] = re.compile(rf'(?P<field>"(?:{"|".join(supported_lang_fields)})":)')
|
164
162
|
|
165
163
|
return metadata
|