ramifice 0.5.11__py3-none-any.whl → 0.6.0__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 +3 -3
- ramifice/commons/__init__.py +5 -5
- ramifice/commons/general.py +2 -2
- ramifice/commons/indexes.py +1 -1
- ramifice/commons/many.py +7 -3
- ramifice/commons/one.py +7 -3
- ramifice/commons/tools.py +1 -1
- ramifice/commons/unit_manager.py +3 -3
- ramifice/fields/__init__.py +28 -28
- ramifice/fields/bool_field.py +3 -3
- ramifice/fields/choice_float_dyn_field.py +4 -4
- ramifice/fields/choice_float_field.py +4 -4
- ramifice/fields/choice_float_mult_dyn_field.py +4 -4
- ramifice/fields/choice_float_mult_field.py +4 -4
- ramifice/fields/choice_int_dyn_field.py +4 -4
- ramifice/fields/choice_int_field.py +4 -4
- ramifice/fields/choice_int_mult_dyn_field.py +4 -4
- ramifice/fields/choice_int_mult_field.py +4 -4
- ramifice/fields/choice_text_dyn_field.py +4 -4
- ramifice/fields/choice_text_field.py +4 -4
- ramifice/fields/choice_text_mult_dyn_field.py +4 -4
- ramifice/fields/choice_text_mult_field.py +4 -4
- ramifice/fields/color_field.py +4 -4
- ramifice/fields/date_field.py +3 -3
- ramifice/fields/date_time_field.py +3 -3
- ramifice/fields/email_field.py +4 -4
- ramifice/fields/file_field.py +19 -18
- ramifice/fields/float_field.py +4 -4
- ramifice/fields/general/__init__.py +1 -1
- ramifice/fields/general/choice_group.py +3 -1
- ramifice/fields/general/date_group.py +2 -1
- ramifice/fields/general/field.py +3 -1
- ramifice/fields/general/file_group.py +3 -1
- ramifice/fields/general/number_group.py +3 -1
- ramifice/fields/general/text_group.py +3 -1
- ramifice/fields/id_field.py +2 -2
- ramifice/fields/image_field.py +18 -37
- ramifice/fields/integer_field.py +4 -4
- ramifice/fields/ip_field.py +4 -4
- ramifice/fields/password_field.py +2 -2
- ramifice/fields/phone_field.py +4 -4
- ramifice/fields/slug_field.py +4 -4
- ramifice/fields/text_field.py +3 -3
- ramifice/fields/url_field.py +4 -4
- ramifice/models/decorator.py +33 -61
- ramifice/models/model.py +2 -2
- ramifice/paladins/__init__.py +6 -6
- ramifice/paladins/check.py +17 -30
- ramifice/paladins/delete.py +6 -6
- ramifice/paladins/groups/__init__.py +10 -10
- ramifice/paladins/groups/bool_group.py +1 -1
- ramifice/paladins/groups/choice_group.py +2 -2
- ramifice/paladins/groups/date_group.py +5 -2
- ramifice/paladins/groups/file_group.py +7 -4
- ramifice/paladins/groups/id_group.py +2 -2
- ramifice/paladins/groups/img_group.py +27 -15
- ramifice/paladins/groups/num_group.py +6 -2
- ramifice/paladins/groups/pass_group.py +3 -3
- ramifice/paladins/groups/slug_group.py +2 -2
- ramifice/paladins/groups/text_group.py +16 -5
- ramifice/paladins/password.py +2 -2
- ramifice/paladins/refrash.py +3 -3
- ramifice/paladins/save.py +3 -3
- ramifice/paladins/tools.py +1 -3
- ramifice/utils/fixtures.py +1 -1
- ramifice/utils/migration.py +5 -7
- ramifice/utils/mixins/__init__.py +4 -4
- ramifice/utils/tools.py +2 -2
- ramifice/utils/translations.py +1 -1
- ramifice/utils/unit.py +2 -2
- {ramifice-0.5.11.dist-info → ramifice-0.6.0.dist-info}/METADATA +4 -17
- ramifice-0.6.0.dist-info/RECORD +84 -0
- ramifice/models/pseudo.py +0 -181
- ramifice-0.5.11.dist-info/RECORD +0 -85
- {ramifice-0.5.11.dist-info → ramifice-0.6.0.dist-info}/WHEEL +0 -0
- {ramifice-0.5.11.dist-info → ramifice-0.6.0.dist-info}/licenses/LICENSE +0 -0
ramifice/fields/image_field.py
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
"""Field of Model for upload image."""
|
2
2
|
|
3
3
|
import os
|
4
|
-
import shutil
|
5
4
|
import uuid
|
6
5
|
from base64 import b64decode
|
7
6
|
from datetime import date
|
8
7
|
from pathlib import Path
|
9
|
-
from typing import Any
|
10
8
|
|
11
|
-
|
9
|
+
import aiofiles
|
10
|
+
from aioshutil import copyfile
|
12
11
|
|
13
|
-
from
|
14
|
-
from
|
15
|
-
from
|
16
|
-
from .
|
17
|
-
from .
|
12
|
+
from ramifice.fields.general.field import Field
|
13
|
+
from ramifice.fields.general.file_group import FileGroup
|
14
|
+
from ramifice.utils import globals
|
15
|
+
from ramifice.utils.errors import FileHasNoExtensionError
|
16
|
+
from ramifice.utils.mixins.json_converter import JsonMixin
|
18
17
|
|
19
18
|
|
20
19
|
class ImageField(Field, FileGroup, JsonMixin):
|
@@ -38,8 +37,6 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
38
37
|
# Available 4 sizes from lg to xs or None.
|
39
38
|
# Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
|
40
39
|
thumbnails: dict[str, int] | None = None,
|
41
|
-
# True - high quality and low performance for thumbnails.
|
42
|
-
high_quality: bool = False,
|
43
40
|
):
|
44
41
|
if globals.DEBUG:
|
45
42
|
if default is not None:
|
@@ -98,8 +95,6 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
98
95
|
raise AssertionError("Parameter `target_dir` - Not а `str` type!")
|
99
96
|
if not isinstance(accept, str):
|
100
97
|
raise AssertionError("Parameter `accept` - Not а `str` type!")
|
101
|
-
if not isinstance(high_quality, bool):
|
102
|
-
raise AssertionError("Parameter `high_quality` - Not а `bool` type!")
|
103
98
|
|
104
99
|
Field.__init__(
|
105
100
|
self,
|
@@ -127,10 +122,8 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
127
122
|
# Available 4 sizes from lg to xs or None.
|
128
123
|
# Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
|
129
124
|
self.thumbnails = thumbnails
|
130
|
-
# True is high quality and low performance.
|
131
|
-
self.high_quality = high_quality
|
132
125
|
|
133
|
-
def from_base64(
|
126
|
+
async def from_base64(
|
134
127
|
self,
|
135
128
|
base64_str: str | None = None,
|
136
129
|
filename: str | None = None,
|
@@ -170,21 +163,15 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
170
163
|
# Create path to main image.
|
171
164
|
main_img_path = f"{imgs_dir_path}/{new_original_name}"
|
172
165
|
# Create target directory if it does not exist.
|
173
|
-
if not os.path.exists(imgs_dir_path):
|
174
|
-
os.makedirs(imgs_dir_path)
|
166
|
+
if not await aiofiles.os.path.exists(imgs_dir_path):
|
167
|
+
await aiofiles.os.makedirs(imgs_dir_path)
|
175
168
|
# Save main image in target directory.
|
176
|
-
with open(main_img_path, mode="wb") as open_f:
|
169
|
+
async with aiofiles.open(main_img_path, mode="wb") as open_f:
|
177
170
|
f_content = b64decode(base64_str)
|
178
|
-
open_f.write(f_content)
|
171
|
+
await open_f.write(f_content)
|
179
172
|
# Add paths for main image.
|
180
173
|
img_info["path"] = main_img_path
|
181
174
|
img_info["url"] = f"{imgs_dir_url}/{new_original_name}"
|
182
|
-
# Add width and height.
|
183
|
-
if self.__dict__.get("add_width_height", False):
|
184
|
-
with Image.open(main_img_path) as img:
|
185
|
-
width, height = img.size
|
186
|
-
img_info["width"] = width
|
187
|
-
img_info["height"] = height
|
188
175
|
# Add original image name.
|
189
176
|
img_info["name"] = filename
|
190
177
|
# Add image extension.
|
@@ -199,12 +186,12 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
199
186
|
# Add url path to target directory with images.
|
200
187
|
img_info["imgs_dir_url"] = imgs_dir_url
|
201
188
|
# Add size of main image (in bytes).
|
202
|
-
img_info["size"] = os.path.getsize(main_img_path)
|
189
|
+
img_info["size"] = await aiofiles.os.path.getsize(main_img_path)
|
203
190
|
#
|
204
191
|
# to value.
|
205
192
|
self.value = img_info
|
206
193
|
|
207
|
-
def from_path(
|
194
|
+
async def from_path(
|
208
195
|
self,
|
209
196
|
src_path: str | None = None,
|
210
197
|
is_delete: bool = False,
|
@@ -234,19 +221,13 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
234
221
|
# Create path to main image.
|
235
222
|
main_img_path = f"{imgs_dir_path}/{new_original_name}"
|
236
223
|
# Create target directory if it does not exist.
|
237
|
-
if not os.path.exists(imgs_dir_path):
|
238
|
-
os.makedirs(imgs_dir_path)
|
224
|
+
if not await aiofiles.os.path.exists(imgs_dir_path):
|
225
|
+
await aiofiles.os.makedirs(imgs_dir_path)
|
239
226
|
# Save main image in target directory.
|
240
|
-
|
227
|
+
await copyfile(src_path, main_img_path)
|
241
228
|
# Add paths for main image.
|
242
229
|
img_info["path"] = main_img_path
|
243
230
|
img_info["url"] = f"{imgs_dir_url}/{new_original_name}"
|
244
|
-
# Add width and height.
|
245
|
-
if self.__dict__.get("add_width_height", False):
|
246
|
-
with Image.open(main_img_path) as img:
|
247
|
-
width, height = img.size
|
248
|
-
img_info["width"] = width
|
249
|
-
img_info["height"] = height
|
250
231
|
# Add original image name.
|
251
232
|
img_info["name"] = os.path.basename(src_path)
|
252
233
|
# Add image extension.
|
@@ -261,7 +242,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
261
242
|
# Add url path to target directory with images.
|
262
243
|
img_info["imgs_dir_url"] = imgs_dir_url
|
263
244
|
# Add size of main image (in bytes).
|
264
|
-
img_info["size"] = os.path.getsize(main_img_path)
|
245
|
+
img_info["size"] = await aiofiles.os.path.getsize(main_img_path)
|
265
246
|
#
|
266
247
|
# to value.
|
267
248
|
self.value = img_info
|
ramifice/fields/integer_field.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
"""Field of Model for enter (int) number."""
|
2
2
|
|
3
|
-
from
|
4
|
-
from
|
5
|
-
from .
|
6
|
-
from .
|
3
|
+
from ramifice.fields.general.field import Field
|
4
|
+
from ramifice.fields.general.number_group import NumberGroup
|
5
|
+
from ramifice.utils import globals
|
6
|
+
from ramifice.utils.mixins.json_converter import JsonMixin
|
7
7
|
|
8
8
|
|
9
9
|
class IntegerField(Field, NumberGroup, JsonMixin):
|
ramifice/fields/ip_field.py
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
import ipaddress
|
4
4
|
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from .
|
8
|
-
from .
|
5
|
+
from ramifice.fields.general.field import Field
|
6
|
+
from ramifice.fields.general.text_group import TextGroup
|
7
|
+
from ramifice.utils import globals
|
8
|
+
from ramifice.utils.mixins.json_converter import JsonMixin
|
9
9
|
|
10
10
|
|
11
11
|
class IPField(Field, TextGroup, JsonMixin):
|
ramifice/fields/phone_field.py
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
import phonenumbers
|
4
4
|
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from .
|
8
|
-
from .
|
5
|
+
from ramifice.fields.general.field import Field
|
6
|
+
from ramifice.fields.general.text_group import TextGroup
|
7
|
+
from ramifice.utils import globals
|
8
|
+
from ramifice.utils.mixins.json_converter import JsonMixin
|
9
9
|
|
10
10
|
|
11
11
|
class PhoneField(Field, TextGroup, JsonMixin):
|
ramifice/fields/slug_field.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
"""Field of Model for automatic generation of string `slug`."""
|
2
2
|
|
3
|
-
from
|
4
|
-
from
|
5
|
-
from .
|
6
|
-
from .
|
3
|
+
from ramifice.fields.general.field import Field
|
4
|
+
from ramifice.fields.general.text_group import TextGroup
|
5
|
+
from ramifice.utils import globals
|
6
|
+
from ramifice.utils.mixins.json_converter import JsonMixin
|
7
7
|
|
8
8
|
|
9
9
|
class SlugField(Field, TextGroup, JsonMixin):
|
ramifice/fields/text_field.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
"""Field of Model for enter text."""
|
2
2
|
|
3
|
-
from
|
4
|
-
from
|
5
|
-
from .
|
3
|
+
from ramifice.fields.general.field import Field
|
4
|
+
from ramifice.utils import globals
|
5
|
+
from ramifice.utils.mixins.json_converter import JsonMixin
|
6
6
|
|
7
7
|
|
8
8
|
class TextField(Field, JsonMixin):
|
ramifice/fields/url_field.py
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
from urllib.parse import urlparse
|
4
4
|
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from .
|
8
|
-
from .
|
5
|
+
from ramifice.fields.general.field import Field
|
6
|
+
from ramifice.fields.general.text_group import TextGroup
|
7
|
+
from ramifice.utils import globals
|
8
|
+
from ramifice.utils.mixins.json_converter import JsonMixin
|
9
9
|
|
10
10
|
|
11
11
|
class URLField(Field, TextGroup, JsonMixin):
|
ramifice/models/decorator.py
CHANGED
@@ -4,23 +4,21 @@ import os
|
|
4
4
|
import re
|
5
5
|
from typing import Any
|
6
6
|
|
7
|
-
from
|
8
|
-
from
|
9
|
-
from
|
10
|
-
from
|
11
|
-
from
|
12
|
-
from
|
13
|
-
from
|
14
|
-
from
|
15
|
-
from .
|
16
|
-
from .pseudo import PseudoModel
|
7
|
+
from ramifice.commons import QCommonsMixin
|
8
|
+
from ramifice.fields import DateTimeField, IDField
|
9
|
+
from ramifice.models.model import Model
|
10
|
+
from ramifice.paladins import QPaladinsMixin
|
11
|
+
from ramifice.utils.errors import DoesNotMatchRegexError, PanicError
|
12
|
+
from ramifice.utils.globals import REGEX
|
13
|
+
from ramifice.utils.mixins.add_valid import AddValidMixin
|
14
|
+
from ramifice.utils.mixins.hooks import HooksMixin
|
15
|
+
from ramifice.utils.mixins.indexing import IndexMixin
|
17
16
|
|
18
17
|
|
19
18
|
def model(
|
20
19
|
service_name: str,
|
21
20
|
fixture_name: str | None = None,
|
22
21
|
db_query_docs_limit: int = 1000,
|
23
|
-
is_migrate_model: bool = True,
|
24
22
|
is_create_doc: bool = True,
|
25
23
|
is_update_doc: bool = True,
|
26
24
|
is_delete_doc: bool = True,
|
@@ -32,8 +30,6 @@ def model(
|
|
32
30
|
raise AssertionError("Parameter `fixture_name` - Must be `str | None` type!")
|
33
31
|
if not isinstance(db_query_docs_limit, int):
|
34
32
|
raise AssertionError("Parameter `db_query_docs_limit` - Must be `int` type!")
|
35
|
-
if not isinstance(is_migrate_model, bool):
|
36
|
-
raise AssertionError("Parameter `is_migrate_model` - Must be `bool` type!")
|
37
33
|
if not isinstance(is_create_doc, bool):
|
38
34
|
raise AssertionError("Parameter `is_create_doc` - Must be `bool` type!")
|
39
35
|
if not isinstance(is_update_doc, bool):
|
@@ -55,53 +51,37 @@ def model(
|
|
55
51
|
raise PanicError(msg)
|
56
52
|
|
57
53
|
attrs = {key: val for key, val in cls.__dict__.items()}
|
58
|
-
|
59
|
-
attrs["__dict__"] = Model.__dict__["__dict__"]
|
60
|
-
else:
|
61
|
-
attrs["__dict__"] = PseudoModel.__dict__["__dict__"]
|
54
|
+
attrs["__dict__"] = Model.__dict__["__dict__"]
|
62
55
|
metadata = {
|
63
56
|
"service_name": service_name,
|
64
57
|
"fixture_name": fixture_name,
|
65
58
|
"db_query_docs_limit": db_query_docs_limit,
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"
|
69
|
-
"is_delete_doc": is_delete_doc if is_migrate_model else False,
|
59
|
+
"is_create_doc": is_create_doc,
|
60
|
+
"is_update_doc": is_update_doc,
|
61
|
+
"is_delete_doc": is_delete_doc,
|
70
62
|
}
|
71
63
|
attrs["META"] = {
|
72
64
|
**metadata,
|
73
|
-
**caching(cls, service_name
|
65
|
+
**caching(cls, service_name),
|
74
66
|
}
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
)
|
89
|
-
else:
|
90
|
-
return type(
|
91
|
-
cls.__name__,
|
92
|
-
(
|
93
|
-
PseudoModel,
|
94
|
-
ValidationMixin,
|
95
|
-
CheckMixin,
|
96
|
-
AddValidMixin,
|
97
|
-
),
|
98
|
-
attrs,
|
99
|
-
)
|
68
|
+
return type(
|
69
|
+
cls.__name__,
|
70
|
+
(
|
71
|
+
Model,
|
72
|
+
QPaladinsMixin,
|
73
|
+
QCommonsMixin,
|
74
|
+
AddValidMixin,
|
75
|
+
IndexMixin,
|
76
|
+
HooksMixin,
|
77
|
+
),
|
78
|
+
attrs,
|
79
|
+
)
|
100
80
|
|
101
81
|
return decorator
|
102
82
|
|
103
83
|
|
104
|
-
def caching(cls: Any, service_name: str
|
84
|
+
def caching(cls: Any, service_name: str) -> dict[str, Any]:
|
105
85
|
"""Add additional metadata to `Model.META`."""
|
106
86
|
metadata: dict[str, Any] = {}
|
107
87
|
model_name: str = cls.__name__
|
@@ -128,11 +108,11 @@ def caching(cls: Any, service_name: str, is_migrate_model: bool) -> dict[str, An
|
|
128
108
|
|
129
109
|
raw_model = cls()
|
130
110
|
raw_model.fields()
|
131
|
-
default_fields: dict[str, Any] = {
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
111
|
+
default_fields: dict[str, Any] = {
|
112
|
+
"_id": IDField(),
|
113
|
+
"created_at": DateTimeField(),
|
114
|
+
"updated_at": DateTimeField(),
|
115
|
+
}
|
136
116
|
fields = {**raw_model.__dict__, **default_fields}
|
137
117
|
for f_name, f_data in fields.items():
|
138
118
|
if not callable(f_data):
|
@@ -147,19 +127,11 @@ def caching(cls: Any, service_name: str, is_migrate_model: bool) -> dict[str, An
|
|
147
127
|
#
|
148
128
|
if not f_data.ignored:
|
149
129
|
# Count fields for migrating.
|
150
|
-
|
151
|
-
count_fields_no_ignored += 1
|
130
|
+
count_fields_no_ignored += 1
|
152
131
|
# Get a dictionary of field names and types.
|
153
132
|
field_name_and_type[f_name] = f_type_str
|
154
133
|
# Build data migration storage for dynamic fields.
|
155
134
|
if "Dyn" in f_data.field_type:
|
156
|
-
if not is_migrate_model:
|
157
|
-
msg = (
|
158
|
-
f"Model: `{cls.__module__}.{model_name}` > "
|
159
|
-
+ f"Field: `{f_name}` => "
|
160
|
-
+ "Dynamic field only for a migrated Model."
|
161
|
-
)
|
162
|
-
raise PanicError(msg)
|
163
135
|
data_dynamic_fields[f_name] = None
|
164
136
|
if f_data.field_type == "TextField" and f_data.multi_language:
|
165
137
|
supported_lang_fields.append(f_name)
|
ramifice/models/model.py
CHANGED
@@ -8,8 +8,8 @@ from babel.dates import format_date, format_datetime
|
|
8
8
|
from bson.objectid import ObjectId
|
9
9
|
from dateutil.parser import parse
|
10
10
|
|
11
|
-
from
|
12
|
-
from
|
11
|
+
from ramifice.fields import DateTimeField, IDField
|
12
|
+
from ramifice.utils import translations
|
13
13
|
|
14
14
|
|
15
15
|
class Model(metaclass=ABCMeta):
|
ramifice/paladins/__init__.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
"""Paladins - Model instance methods."""
|
2
2
|
|
3
|
-
from .check import CheckMixin
|
4
|
-
from .delete import DeleteMixin
|
5
|
-
from .password import PasswordMixin
|
6
|
-
from .refrash import RefrashMixin
|
7
|
-
from .save import SaveMixin
|
8
|
-
from .validation import ValidationMixin
|
3
|
+
from ramifice.paladins.check import CheckMixin
|
4
|
+
from ramifice.paladins.delete import DeleteMixin
|
5
|
+
from ramifice.paladins.password import PasswordMixin
|
6
|
+
from ramifice.paladins.refrash import RefrashMixin
|
7
|
+
from ramifice.paladins.save import SaveMixin
|
8
|
+
from ramifice.paladins.validation import ValidationMixin
|
9
9
|
|
10
10
|
|
11
11
|
class QPaladinsMixin(
|
ramifice/paladins/check.py
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
"""Validation of Model data before saving to the database."""
|
2
2
|
|
3
|
-
import os
|
4
|
-
import shutil
|
5
3
|
from typing import Any
|
6
4
|
|
5
|
+
from aiofiles import os
|
6
|
+
from aioshutil import rmtree
|
7
7
|
from bson.objectid import ObjectId
|
8
8
|
from pymongo.asynchronous.collection import AsyncCollection
|
9
9
|
|
10
|
-
from
|
11
|
-
from ..utils.errors import PanicError
|
12
|
-
from .groups import (
|
10
|
+
from ramifice.paladins.groups import (
|
13
11
|
BoolGroupMixin,
|
14
12
|
ChoiceGroupMixin,
|
15
13
|
DateGroupMixin,
|
@@ -21,6 +19,8 @@ from .groups import (
|
|
21
19
|
SlugGroupMixin,
|
22
20
|
TextGroupMixin,
|
23
21
|
)
|
22
|
+
from ramifice.utils import globals
|
23
|
+
from ramifice.utils.errors import PanicError
|
24
24
|
|
25
25
|
|
26
26
|
class CheckMixin(
|
@@ -48,27 +48,15 @@ class CheckMixin(
|
|
48
48
|
It is also used to verify Models that do not migrate to the database.
|
49
49
|
"""
|
50
50
|
cls_model = self.__class__
|
51
|
-
is_migrate_model: bool = cls_model.META["is_migrate_model"]
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
doc_id: ObjectId | None = None
|
62
|
-
is_update: bool = False
|
63
|
-
if is_migrate_model:
|
64
|
-
# Get the document ID.
|
65
|
-
doc_id = self._id.value
|
66
|
-
# Does the document exist in the database?
|
67
|
-
is_update = doc_id is not None
|
68
|
-
# Create an identifier for a new document.
|
69
|
-
if is_save and not is_update:
|
70
|
-
doc_id = ObjectId()
|
71
|
-
self._id.value = doc_id
|
52
|
+
# Get the document ID.
|
53
|
+
doc_id: ObjectId | None = self._id.value
|
54
|
+
# Does the document exist in the database?
|
55
|
+
is_update: bool = doc_id is not None
|
56
|
+
# Create an identifier for a new document.
|
57
|
+
if is_save and not is_update:
|
58
|
+
doc_id = ObjectId()
|
59
|
+
self._id.value = doc_id
|
72
60
|
|
73
61
|
result_map: dict[str, Any] = {}
|
74
62
|
# Errors from additional validation of fields.
|
@@ -86,7 +74,6 @@ class CheckMixin(
|
|
86
74
|
"collection": collection,
|
87
75
|
"field_data": None,
|
88
76
|
"full_model_name": cls_model.META["full_model_name"],
|
89
|
-
"is_migrate_model": is_migrate_model,
|
90
77
|
"is_migration_process": is_migration_process,
|
91
78
|
"curr_doc": (
|
92
79
|
await collection.find_one({"_id": doc_id}) if is_save and is_update else None
|
@@ -116,9 +103,9 @@ class CheckMixin(
|
|
116
103
|
elif group == "date":
|
117
104
|
self.date_group(params)
|
118
105
|
elif group == "img":
|
119
|
-
self.img_group(params)
|
106
|
+
await self.img_group(params)
|
120
107
|
elif group == "file":
|
121
|
-
self.file_group(params)
|
108
|
+
await self.file_group(params)
|
122
109
|
elif group == "choice":
|
123
110
|
self.choice_group(params)
|
124
111
|
elif group == "bool":
|
@@ -146,7 +133,7 @@ class CheckMixin(
|
|
146
133
|
file_data = result_map.get(field_name)
|
147
134
|
if file_data is not None:
|
148
135
|
if file_data["is_new_file"]:
|
149
|
-
os.remove(file_data["path"])
|
136
|
+
await os.remove(file_data["path"])
|
150
137
|
field_data.value = None
|
151
138
|
if curr_doc is not None:
|
152
139
|
field_data.value = curr_doc[field_name]
|
@@ -154,7 +141,7 @@ class CheckMixin(
|
|
154
141
|
img_data = result_map.get(field_name)
|
155
142
|
if img_data is not None:
|
156
143
|
if img_data["is_new_img"]:
|
157
|
-
|
144
|
+
await rmtree(img_data["imgs_dir_path"]) # type: ignore[call-arg]
|
158
145
|
field_data.value = None
|
159
146
|
if curr_doc is not None:
|
160
147
|
field_data.value = curr_doc[field_name]
|
ramifice/paladins/delete.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
"""Delete document from database."""
|
2
2
|
|
3
|
-
import os
|
4
|
-
import shutil
|
5
3
|
from typing import Any
|
6
4
|
|
5
|
+
from aiofiles import os
|
6
|
+
from aioshutil import rmtree
|
7
7
|
from pymongo.asynchronous.collection import AsyncCollection
|
8
8
|
|
9
|
-
from
|
10
|
-
from
|
9
|
+
from ramifice.utils import globals
|
10
|
+
from ramifice.utils.errors import PanicError
|
11
11
|
|
12
12
|
|
13
13
|
class DeleteMixin:
|
@@ -77,12 +77,12 @@ class DeleteMixin:
|
|
77
77
|
if group == "file":
|
78
78
|
file_data = mongo_doc[field_name]
|
79
79
|
if file_data is not None and len(file_data["path"]) > 0:
|
80
|
-
os.remove(file_data["path"])
|
80
|
+
await os.remove(file_data["path"])
|
81
81
|
file_data = None
|
82
82
|
elif group == "img":
|
83
83
|
file_data = mongo_doc[field_name]
|
84
84
|
if file_data is not None and len(file_data["imgs_dir_path"]) > 0:
|
85
|
-
|
85
|
+
await rmtree(file_data["imgs_dir_path"]) # type: ignore[call-arg]
|
86
86
|
file_data = None
|
87
87
|
field_data.value = None
|
88
88
|
# Run hook.
|
@@ -1,12 +1,12 @@
|
|
1
1
|
"""Groups - Model instance methods for specific processing of fields."""
|
2
2
|
|
3
|
-
from .bool_group import BoolGroupMixin
|
4
|
-
from .choice_group import ChoiceGroupMixin
|
5
|
-
from .date_group import DateGroupMixin
|
6
|
-
from .file_group import FileGroupMixin
|
7
|
-
from .id_group import IDGroupMixin
|
8
|
-
from .img_group import ImgGroupMixin
|
9
|
-
from .num_group import NumGroupMixin
|
10
|
-
from .pass_group import PassGroupMixin
|
11
|
-
from .slug_group import SlugGroupMixin
|
12
|
-
from .text_group import TextGroupMixin
|
3
|
+
from ramifice.paladins.groups.bool_group import BoolGroupMixin
|
4
|
+
from ramifice.paladins.groups.choice_group import ChoiceGroupMixin
|
5
|
+
from ramifice.paladins.groups.date_group import DateGroupMixin
|
6
|
+
from ramifice.paladins.groups.file_group import FileGroupMixin
|
7
|
+
from ramifice.paladins.groups.id_group import IDGroupMixin
|
8
|
+
from ramifice.paladins.groups.img_group import ImgGroupMixin
|
9
|
+
from ramifice.paladins.groups.num_group import NumGroupMixin
|
10
|
+
from ramifice.paladins.groups.pass_group import PassGroupMixin
|
11
|
+
from ramifice.paladins.groups.slug_group import SlugGroupMixin
|
12
|
+
from ramifice.paladins.groups.text_group import TextGroupMixin
|
@@ -9,8 +9,11 @@ from typing import Any
|
|
9
9
|
|
10
10
|
from babel.dates import format_date, format_datetime
|
11
11
|
|
12
|
-
from
|
13
|
-
|
12
|
+
from ramifice.paladins.tools import (
|
13
|
+
accumulate_error,
|
14
|
+
panic_type_error,
|
15
|
+
)
|
16
|
+
from ramifice.utils import translations
|
14
17
|
|
15
18
|
|
16
19
|
class DateGroupMixin:
|
@@ -5,9 +5,12 @@ Supported fields: FileField
|
|
5
5
|
|
6
6
|
from typing import Any
|
7
7
|
|
8
|
-
from
|
9
|
-
|
10
|
-
|
8
|
+
from ramifice.paladins.tools import (
|
9
|
+
accumulate_error,
|
10
|
+
panic_type_error,
|
11
|
+
)
|
12
|
+
from ramifice.utils import translations
|
13
|
+
from ramifice.utils.tools import to_human_size
|
11
14
|
|
12
15
|
|
13
16
|
class FileGroupMixin:
|
@@ -16,7 +19,7 @@ class FileGroupMixin:
|
|
16
19
|
Supported fields: FileField
|
17
20
|
"""
|
18
21
|
|
19
|
-
def file_group(self, params: dict[str, Any]) -> None:
|
22
|
+
async def file_group(self, params: dict[str, Any]) -> None:
|
20
23
|
"""Checking file fields."""
|
21
24
|
field = params["field_data"]
|
22
25
|
value = field.value or None
|
@@ -8,8 +8,8 @@ from typing import Any
|
|
8
8
|
|
9
9
|
from bson.objectid import ObjectId
|
10
10
|
|
11
|
-
from
|
12
|
-
from
|
11
|
+
from ramifice.paladins.tools import accumulate_error, panic_type_error
|
12
|
+
from ramifice.utils import translations
|
13
13
|
|
14
14
|
|
15
15
|
class IDGroupMixin:
|