ramifice 0.3.18__py3-none-any.whl → 0.3.19__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/decorators.py +1 -1
- ramifice/fields/file_field.py +4 -5
- ramifice/fields/image_field.py +4 -5
- ramifice/migration.py +12 -7
- ramifice/model.py +20 -1
- ramifice/paladins/groups/file_group.py +1 -8
- ramifice/paladins/groups/img_group.py +0 -7
- ramifice/store.py +0 -40
- {ramifice-0.3.18.dist-info → ramifice-0.3.19.dist-info}/METADATA +1 -1
- {ramifice-0.3.18.dist-info → ramifice-0.3.19.dist-info}/RECORD +12 -12
- {ramifice-0.3.18.dist-info → ramifice-0.3.19.dist-info}/WHEEL +0 -0
- {ramifice-0.3.18.dist-info → ramifice-0.3.19.dist-info}/licenses/LICENSE +0 -0
ramifice/decorators.py
CHANGED
@@ -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 = cls.__name__
|
102
102
|
if REGEX["model_name"].match(model_name) is None:
|
ramifice/fields/file_field.py
CHANGED
@@ -102,7 +102,7 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
102
102
|
""" # noqa: D205
|
103
103
|
base64_str = base64_str or None
|
104
104
|
filename = filename or None
|
105
|
-
file_info =
|
105
|
+
file_info: dict[str, str | int | bool] = {"save_as_is": False}
|
106
106
|
file_info["is_new_file"] = True
|
107
107
|
file_info["is_delete"] = is_delete
|
108
108
|
|
@@ -142,11 +142,10 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
142
142
|
file_info["extension"] = extension
|
143
143
|
# Add file size (in bytes).
|
144
144
|
file_info["size"] = os.path.getsize(f_target_path)
|
145
|
-
|
145
|
+
#
|
146
146
|
# to value.
|
147
147
|
self.value = file_info
|
148
148
|
|
149
|
-
# --------------------------------------------------------------------------
|
150
149
|
def from_path(
|
151
150
|
self,
|
152
151
|
src_path: str | None = None,
|
@@ -154,7 +153,7 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
154
153
|
) -> None:
|
155
154
|
"""Get file information and copy the file to the target directory."""
|
156
155
|
src_path = src_path or None
|
157
|
-
file_info =
|
156
|
+
file_info: dict[str, str | int | bool] = {"save_as_is": False}
|
158
157
|
file_info["is_new_file"] = True
|
159
158
|
file_info["is_delete"] = is_delete
|
160
159
|
|
@@ -186,6 +185,6 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
186
185
|
file_info["extension"] = extension
|
187
186
|
# Add file size (in bytes).
|
188
187
|
file_info["size"] = os.path.getsize(f_target_path)
|
189
|
-
|
188
|
+
#
|
190
189
|
# to value.
|
191
190
|
self.value = file_info
|
ramifice/fields/image_field.py
CHANGED
@@ -142,7 +142,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
142
142
|
""" # noqa: D205
|
143
143
|
base64_str = base64_str or None
|
144
144
|
filename = filename or None
|
145
|
-
img_info =
|
145
|
+
img_info: dict[str, str | int | bool] = {"save_as_is": False}
|
146
146
|
img_info["is_new_img"] = True
|
147
147
|
img_info["is_delete"] = is_delete
|
148
148
|
|
@@ -201,11 +201,10 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
201
201
|
img_info["imgs_dir_url"] = imgs_dir_url
|
202
202
|
# Add size of main image (in bytes).
|
203
203
|
img_info["size"] = os.path.getsize(main_img_path)
|
204
|
-
|
204
|
+
#
|
205
205
|
# to value.
|
206
206
|
self.value = img_info
|
207
207
|
|
208
|
-
# --------------------------------------------------------------------------
|
209
208
|
def from_path(
|
210
209
|
self,
|
211
210
|
src_path: str | None = None,
|
@@ -214,7 +213,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
214
213
|
) -> None:
|
215
214
|
"""Get image information and copy the image to the target directory."""
|
216
215
|
src_path = src_path or None
|
217
|
-
img_info =
|
216
|
+
img_info: dict[str, str | int | bool] = {"save_as_is": False}
|
218
217
|
img_info["is_new_img"] = True
|
219
218
|
img_info["is_delete"] = is_delete
|
220
219
|
|
@@ -265,6 +264,6 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
265
264
|
img_info["imgs_dir_url"] = imgs_dir_url
|
266
265
|
# Add size of main image (in bytes).
|
267
266
|
img_info["size"] = os.path.getsize(main_img_path)
|
268
|
-
|
267
|
+
#
|
269
268
|
# to value.
|
270
269
|
self.value = img_info
|
ramifice/migration.py
CHANGED
@@ -15,7 +15,6 @@ from . import store
|
|
15
15
|
from .errors import DoesNotMatchRegexError, NoModelsForMigrationError, PanicError
|
16
16
|
from .fixtures import apply_fixture
|
17
17
|
from .model import Model
|
18
|
-
from .store import FILE_INFO_DICT, IMG_INFO_DICT
|
19
18
|
|
20
19
|
|
21
20
|
class Monitor:
|
@@ -137,13 +136,19 @@ class Monitor:
|
|
137
136
|
field_type = metadata["field_name_and_type"].get(field_name)
|
138
137
|
if field_type is not None:
|
139
138
|
if field_type == "FileField":
|
140
|
-
|
141
|
-
|
142
|
-
|
139
|
+
file_info = {
|
140
|
+
"path": "",
|
141
|
+
"is_delete": True,
|
142
|
+
"save_as_is": False,
|
143
|
+
}
|
144
|
+
mongo_doc[field_name] = file_info
|
143
145
|
elif field_type == "ImageField":
|
144
|
-
|
145
|
-
|
146
|
-
|
146
|
+
img_info = {
|
147
|
+
"path": "",
|
148
|
+
"is_delete": True,
|
149
|
+
"save_as_is": False,
|
150
|
+
}
|
151
|
+
mongo_doc[field_name] = img_info
|
147
152
|
else:
|
148
153
|
mongo_doc[field_name] = None
|
149
154
|
#
|
ramifice/model.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
"""For converting Python classes into Ramifice Model."""
|
2
2
|
|
3
|
-
import copy
|
4
3
|
import json
|
4
|
+
import os
|
5
|
+
import shutil
|
5
6
|
from abc import ABCMeta, abstractmethod
|
6
7
|
from typing import Any
|
7
8
|
|
@@ -46,6 +47,24 @@ class Model(metaclass=ABCMeta):
|
|
46
47
|
self.fields()
|
47
48
|
self.inject()
|
48
49
|
|
50
|
+
def __del__(self) -> None: # noqa: D105
|
51
|
+
# If the model is not migrated,
|
52
|
+
# it must delete files and images in the destructor.
|
53
|
+
if not self.__class__.META["is_migrate_model"]:
|
54
|
+
for _, f_type in self.__dict__.items():
|
55
|
+
if not callable(f_type):
|
56
|
+
value = f_type.value
|
57
|
+
if value is None:
|
58
|
+
continue
|
59
|
+
if f_type.group == "file":
|
60
|
+
value = value.get("path")
|
61
|
+
if value is not None:
|
62
|
+
os.remove(value)
|
63
|
+
elif f_type.group == "img":
|
64
|
+
value = value.get("imgs_dir_path")
|
65
|
+
if value is not None:
|
66
|
+
shutil.rmtree(value)
|
67
|
+
|
49
68
|
@abstractmethod
|
50
69
|
def fields(self) -> None:
|
51
70
|
"""For adding fields."""
|
@@ -3,7 +3,6 @@
|
|
3
3
|
Supported fields: FileField
|
4
4
|
"""
|
5
5
|
|
6
|
-
import os
|
7
6
|
from typing import Any
|
8
7
|
|
9
8
|
from ... import translations
|
@@ -46,7 +45,7 @@ class FileGroupMixin:
|
|
46
45
|
return
|
47
46
|
if not value["save_as_is"]:
|
48
47
|
# If the file needs to be delete.
|
49
|
-
if value["is_delete"] and len(value
|
48
|
+
if value["is_delete"] and len(value["path"]) == 0:
|
50
49
|
default = field.default or None
|
51
50
|
# If necessary, use the default value.
|
52
51
|
if default is not None:
|
@@ -67,12 +66,6 @@ class FileGroupMixin:
|
|
67
66
|
)
|
68
67
|
accumulate_error(params["full_model_name"], err_msg, params)
|
69
68
|
return
|
70
|
-
# Return if there is no need to save.
|
71
|
-
if not params["is_save"]:
|
72
|
-
if value["is_new_file"]:
|
73
|
-
os.remove(value["path"])
|
74
|
-
params["field_data"].value = None
|
75
|
-
return
|
76
69
|
# Insert result.
|
77
70
|
if params["is_save"] and (value["is_new_file"] or value["save_as_is"]):
|
78
71
|
value["is_delete"] = False
|
@@ -3,7 +3,6 @@
|
|
3
3
|
Supported fields: ImageField
|
4
4
|
"""
|
5
5
|
|
6
|
-
import shutil
|
7
6
|
from typing import Any
|
8
7
|
|
9
8
|
from PIL import Image
|
@@ -69,12 +68,6 @@ class ImgGroupMixin:
|
|
69
68
|
)
|
70
69
|
accumulate_error(params["full_model_name"], err_msg, params)
|
71
70
|
return
|
72
|
-
# Return if there is no need to save.
|
73
|
-
if not params["is_save"]:
|
74
|
-
if value["is_new_img"]:
|
75
|
-
shutil.rmtree(value["imgs_dir_path"])
|
76
|
-
params["field_data"].value = None
|
77
|
-
return
|
78
71
|
# Create thumbnails.
|
79
72
|
if value["is_new_img"]:
|
80
73
|
thumbnails = field.thumbnails
|
ramifice/store.py
CHANGED
@@ -43,43 +43,3 @@ REGEX: dict[str, re.Pattern] = {
|
|
43
43
|
),
|
44
44
|
"password": re.compile(r'^[-._!"`\'#%&,:;<>=@{}~\$\(\)\*\+\/\\\?\[\]\^\|a-zA-Z0-9]{8,256}$'),
|
45
45
|
}
|
46
|
-
|
47
|
-
# Caching a dictionary to transmit information about the file.
|
48
|
-
# Hint: `FileField.value`.
|
49
|
-
FILE_INFO_DICT: dict[str, str | int | bool] = dict(
|
50
|
-
path="",
|
51
|
-
url="",
|
52
|
-
name="",
|
53
|
-
size=0,
|
54
|
-
is_new_file=False,
|
55
|
-
is_delete=False,
|
56
|
-
extension="",
|
57
|
-
save_as_is=False,
|
58
|
-
)
|
59
|
-
|
60
|
-
# Caching a dictionary to transmit information about the image.
|
61
|
-
# Hint: `ImageField.value`.
|
62
|
-
IMG_INFO_DICT: dict[str, str | int | bool] = dict(
|
63
|
-
path="",
|
64
|
-
path_xs="",
|
65
|
-
path_sm="",
|
66
|
-
path_md="",
|
67
|
-
path_lg="",
|
68
|
-
url="",
|
69
|
-
url_xs="",
|
70
|
-
url_sm="",
|
71
|
-
url_md="",
|
72
|
-
url_lg="",
|
73
|
-
name="",
|
74
|
-
width=0,
|
75
|
-
height=0,
|
76
|
-
size=0,
|
77
|
-
is_new_img=False,
|
78
|
-
is_delete=False,
|
79
|
-
extension="",
|
80
|
-
imgs_dir_path="",
|
81
|
-
imgs_dir_url="",
|
82
|
-
save_as_is=False,
|
83
|
-
# Extension to the upper register and delete the point.
|
84
|
-
ext_upper="",
|
85
|
-
)
|
@@ -1,15 +1,15 @@
|
|
1
1
|
ramifice/__init__.py,sha256=ISlaL2BprlJLE_N1fvtAqGrB3Dhniy9IZGoyWEYZhRU,678
|
2
2
|
ramifice/add_valid.py,sha256=kvpMg7snL9tor0A23XRdgwiXazRwHfb8baoJUNjM_4Y,327
|
3
|
-
ramifice/decorators.py,sha256=
|
3
|
+
ramifice/decorators.py,sha256=rOM8b_5FHQ02rdxuRL-LUd5oV_MB-RDGXVfdjMUWuGY,6143
|
4
4
|
ramifice/errors.py,sha256=iuhq7fzpUmsOyeXeg2fJjta8yAuqlXLKsZVMpfUhtHE,1901
|
5
5
|
ramifice/fixtures.py,sha256=NtxOnZslYJb4yvRpZbs3ckugmTwHQFS_9iCt2zddOC0,3102
|
6
6
|
ramifice/hooks.py,sha256=Ri-ISfMT-IHaLO2eAqg8CODCTs3HRTxSylqspUKnVf4,873
|
7
7
|
ramifice/indexing.py,sha256=wQpX2qei5Zc7iIq5yIV93Skp8Aa8ZD0vybnEk7cRuXs,271
|
8
|
-
ramifice/migration.py,sha256=
|
8
|
+
ramifice/migration.py,sha256=t_Rm1OUQYrlaPQQd1uS5S7EYMvSuKUcWzi7P4JMkrOw,11114
|
9
9
|
ramifice/mixins.py,sha256=gKLmWQ-QrGO3K5_k-h1tDa08lkCql_dte2Jy05q1wsM,1125
|
10
|
-
ramifice/model.py,sha256=
|
10
|
+
ramifice/model.py,sha256=FnBEsKJhYHL3HZTGRC1_UaLlBh7BJS_O8qCRYCFavhg,7365
|
11
11
|
ramifice/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
ramifice/store.py,sha256=
|
12
|
+
ramifice/store.py,sha256=MpDEPvUvbs11FXjakNtHPm9MekIv5p1U3as2Y80lTyc,1860
|
13
13
|
ramifice/translations.py,sha256=GNGE0ULAA0aOY5pTxUd3MQW-nVaKvp6BeXWEcsR0s0o,4048
|
14
14
|
ramifice/types.py,sha256=ljo6VscUGWEJ4Km4JYo8GEfxd1YK1CUbS8CfHp_MlEA,2390
|
15
15
|
ramifice/utilities.py,sha256=c662nwFcWXSXNYfwqDnGlLWpA01KaK79GwTdApqtMh8,2442
|
@@ -38,10 +38,10 @@ ramifice/fields/color_field.py,sha256=sjVSoJU6TIZ66wzPx0WRl5zQsx-kINMMuxa_pSUpW6
|
|
38
38
|
ramifice/fields/date_field.py,sha256=Vlaxgp3WeDNMwbnQcTGu8kyQ7gc7M-7sFBPfzu-4MVw,5205
|
39
39
|
ramifice/fields/date_time_field.py,sha256=VpLeYJHs0df45fz4gnprtn7aipVFKGY4n02eRep7in0,5240
|
40
40
|
ramifice/fields/email_field.py,sha256=wOM07nQ5fOSOTydQhg3b4dV_95F1bd97peQ_XAnV0MY,3720
|
41
|
-
ramifice/fields/file_field.py,sha256
|
41
|
+
ramifice/fields/file_field.py,sha256=Ofui6MFme78v_U_pWu8chpN3FnCW5cKQmnqmJOCi2VE,7922
|
42
42
|
ramifice/fields/float_field.py,sha256=4l7gzg46qQ7ZbXS6Z8GUhiUBR26rXChvO_uFx-lbUds,4555
|
43
43
|
ramifice/fields/id_field.py,sha256=5wlY2j051TB2GPsw0iQkFiQBV_Y_o1W_QnCtBlaDuYQ,4126
|
44
|
-
ramifice/fields/image_field.py,sha256=
|
44
|
+
ramifice/fields/image_field.py,sha256=flh08BZnluez-XvL-ucIS61Km_oZO8HCA5105hpHfTE,12285
|
45
45
|
ramifice/fields/integer_field.py,sha256=Gnm5IBSvWtCLGbg5pOSAdKa5xLzqXgiigVbzw8zcjas,4531
|
46
46
|
ramifice/fields/ip_field.py,sha256=D7xR3A-O049TQ_pEEKVTLsKF5cdr5O7ULyz4Pj3-cwQ,3601
|
47
47
|
ramifice/fields/password_field.py,sha256=5BlZZ4mXM0CAYDHguwsK8KFnvkOOmr8R0yowHByNVD4,3451
|
@@ -68,14 +68,14 @@ ramifice/paladins/groups/__init__.py,sha256=hpqmWLsYAMvZHAbmMXluQSqLhkHOSTUAgLHy
|
|
68
68
|
ramifice/paladins/groups/bool_group.py,sha256=fpxCySJ5JL7w1dLFPX1025zEU8CRsWSyQyXb3Hr3Z2s,819
|
69
69
|
ramifice/paladins/groups/choice_group.py,sha256=OJeZjpnqKnSF1_bechtNepCCPjmp54x1T0c28DAa11c,1777
|
70
70
|
ramifice/paladins/groups/date_group.py,sha256=-IS9pAHXdWK7tO9KQ2UyG1uf7TA43DKYCOCtOM2_tZ0,3844
|
71
|
-
ramifice/paladins/groups/file_group.py,sha256=
|
71
|
+
ramifice/paladins/groups/file_group.py,sha256=9GzRY3sV8PYJh23ZPtMQYH5RDi4pibN-kIaSui4B5zY,3033
|
72
72
|
ramifice/paladins/groups/id_group.py,sha256=tK3OL1pr-V8PHPyS7vmjmJi_sRU669EvkY_Fc4sRHzg,1352
|
73
|
-
ramifice/paladins/groups/img_group.py,sha256=
|
73
|
+
ramifice/paladins/groups/img_group.py,sha256=j184UyyYZ8gNuAivkP1A57o9JlrGS_0sht6QKiblbDs,5643
|
74
74
|
ramifice/paladins/groups/num_group.py,sha256=Jvb-lwHxapQybbLerC4t-_yO8N7Coo1fIlZ9eAGHcGs,2508
|
75
75
|
ramifice/paladins/groups/pass_group.py,sha256=SEKpR2voNQtmywugDXJKY4XqPTL91CrJ87h0QNMqQqs,1952
|
76
76
|
ramifice/paladins/groups/slug_group.py,sha256=_IRil2PwpY7cH7WaExNksKz61kQjvc27blrEufgUB30,2323
|
77
77
|
ramifice/paladins/groups/text_group.py,sha256=nYZGwAIsJD-tX8RBtFlWvngO9RU4V0CnREUhxvV2UDo,3493
|
78
|
-
ramifice-0.3.
|
79
|
-
ramifice-0.3.
|
80
|
-
ramifice-0.3.
|
81
|
-
ramifice-0.3.
|
78
|
+
ramifice-0.3.19.dist-info/METADATA,sha256=uaJt29S3kOMiBjlopixQuCRIu-O8MvdAeUzQDwJHr2I,18904
|
79
|
+
ramifice-0.3.19.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
80
|
+
ramifice-0.3.19.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
|
81
|
+
ramifice-0.3.19.dist-info/RECORD,,
|
File without changes
|
File without changes
|