ramifice 0.4.7__py3-none-any.whl → 0.4.9__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 +1 -0
- ramifice/commons/general.py +21 -1
- ramifice/commons/one.py +3 -3
- ramifice/commons/tools.py +0 -18
- ramifice/utils/fixtures.py +2 -1
- ramifice/utils/migration.py +10 -9
- {ramifice-0.4.7.dist-info → ramifice-0.4.9.dist-info}/METADATA +7 -2
- {ramifice-0.4.7.dist-info → ramifice-0.4.9.dist-info}/RECORD +10 -10
- {ramifice-0.4.7.dist-info → ramifice-0.4.9.dist-info}/WHEEL +0 -0
- {ramifice-0.4.7.dist-info → ramifice-0.4.9.dist-info}/licenses/LICENSE +0 -0
ramifice/__init__.py
CHANGED
ramifice/commons/general.py
CHANGED
@@ -6,12 +6,32 @@ from pymongo.asynchronous.collection import AsyncCollection
|
|
6
6
|
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
|
7
7
|
from pymongo.asynchronous.database import AsyncDatabase
|
8
8
|
|
9
|
-
from ..utils import globals
|
9
|
+
from ..utils import globals, translations
|
10
10
|
|
11
11
|
|
12
12
|
class GeneralMixin:
|
13
13
|
"""General purpose query methods."""
|
14
14
|
|
15
|
+
@classmethod
|
16
|
+
def from_mongo_doc(
|
17
|
+
cls,
|
18
|
+
mongo_doc: dict[str, Any],
|
19
|
+
) -> Any:
|
20
|
+
"""Create object instance from Mongo document."""
|
21
|
+
obj: Any = cls()
|
22
|
+
lang: str = translations.CURRENT_LOCALE
|
23
|
+
for name, data in mongo_doc.items():
|
24
|
+
field = obj.__dict__.get(name)
|
25
|
+
if field is None:
|
26
|
+
continue
|
27
|
+
if field.field_type == "TextField":
|
28
|
+
field.value = data.get(lang, "") if data is not None else None
|
29
|
+
elif field.group == "pass":
|
30
|
+
field.value = None
|
31
|
+
else:
|
32
|
+
field.value = data
|
33
|
+
return obj
|
34
|
+
|
15
35
|
@classmethod
|
16
36
|
async def estimated_document_count( # type: ignore[no-untyped-def]
|
17
37
|
cls,
|
ramifice/commons/one.py
CHANGED
@@ -7,7 +7,7 @@ from pymongo.results import DeleteResult
|
|
7
7
|
|
8
8
|
from ..utils import globals
|
9
9
|
from ..utils.errors import PanicError
|
10
|
-
from .tools import
|
10
|
+
from .tools import mongo_doc_to_raw_doc, password_to_none
|
11
11
|
|
12
12
|
|
13
13
|
class OneMixin:
|
@@ -67,7 +67,7 @@ class OneMixin:
|
|
67
67
|
mongo_doc = await collection.find_one(filter, *args, **kwargs)
|
68
68
|
if mongo_doc is not None:
|
69
69
|
# Convert document to Model instance.
|
70
|
-
inst_model = from_mongo_doc(
|
70
|
+
inst_model = cls.from_mongo_doc(mongo_doc)
|
71
71
|
return inst_model
|
72
72
|
|
73
73
|
@classmethod
|
@@ -85,7 +85,7 @@ class OneMixin:
|
|
85
85
|
mongo_doc = await collection.find_one(filter, *args, **kwargs)
|
86
86
|
if mongo_doc is not None:
|
87
87
|
# Convert document to Model instance.
|
88
|
-
inst_model = from_mongo_doc(
|
88
|
+
inst_model = cls.from_mongo_doc( mongo_doc)
|
89
89
|
json_str = inst_model.to_json()
|
90
90
|
return json_str
|
91
91
|
|
ramifice/commons/tools.py
CHANGED
@@ -18,24 +18,6 @@ def password_to_none(
|
|
18
18
|
return mongo_doc
|
19
19
|
|
20
20
|
|
21
|
-
def from_mongo_doc(
|
22
|
-
cls_model: Any,
|
23
|
-
mongo_doc: dict[str, Any],
|
24
|
-
) -> Any:
|
25
|
-
"""Create object instance from Mongo document."""
|
26
|
-
obj: Any = cls_model()
|
27
|
-
lang: str = translations.CURRENT_LOCALE
|
28
|
-
for name, data in mongo_doc.items():
|
29
|
-
field = obj.__dict__[name]
|
30
|
-
if field.field_type == "TextField":
|
31
|
-
field.value = data.get(lang, "") if data is not None else None
|
32
|
-
elif field.group == "pass":
|
33
|
-
field.value = None
|
34
|
-
else:
|
35
|
-
field.value = data
|
36
|
-
return obj
|
37
|
-
|
38
|
-
|
39
21
|
def mongo_doc_to_raw_doc(
|
40
22
|
field_name_and_type: dict[str, str],
|
41
23
|
mongo_doc: dict[str, Any],
|
ramifice/utils/fixtures.py
CHANGED
@@ -68,7 +68,8 @@ async def apply_fixture(
|
|
68
68
|
print(colored("\nFIXTURE:", "red", attrs=["bold"]))
|
69
69
|
print(colored(fixture_path, "blue", attrs=["bold"]))
|
70
70
|
inst_model.print_err()
|
71
|
-
|
71
|
+
msg = f"Fixture `{fixture_name}` failed."
|
72
|
+
raise PanicError(msg)
|
72
73
|
# Get data for document.
|
73
74
|
checked_data: dict[str, Any] = result_check["data"]
|
74
75
|
# Add date and time.
|
ramifice/utils/migration.py
CHANGED
@@ -174,20 +174,21 @@ class Monitor:
|
|
174
174
|
checked_data["updated_at"] = datetime.now()
|
175
175
|
# Update the document in the database.
|
176
176
|
await model_collection.replace_one(
|
177
|
-
filter={"_id": checked_data["_id"]},
|
177
|
+
filter={"_id": checked_data["_id"]},
|
178
|
+
replacement=checked_data,
|
178
179
|
)
|
179
180
|
#
|
180
181
|
# Refresh the dynamic fields data for the current model.
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
182
|
+
for field_name, field_data in metadata["data_dynamic_fields"].items():
|
183
|
+
if model_state["data_dynamic_fields"].get(field_name, False) == False:
|
184
|
+
model_state["data_dynamic_fields"][field_name] = field_data
|
185
|
+
else:
|
186
|
+
metadata["data_dynamic_fields"][field_name] = model_state[
|
187
|
+
"data_dynamic_fields"
|
188
|
+
][field_name]
|
189
|
+
# Refresh state of current Model.
|
188
190
|
model_state["data_dynamic_field"] = metadata["data_dynamic_fields"]
|
189
191
|
model_state["field_name_and_type"] = metadata["field_name_and_type"]
|
190
|
-
# Refresh state of current Model.
|
191
192
|
await super_collection.replace_one(
|
192
193
|
filter={"collection_name": model_state["collection_name"]},
|
193
194
|
replacement=model_state,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: ramifice
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.9
|
4
4
|
Summary: ORM-like API MongoDB for Python language.
|
5
5
|
Project-URL: Homepage, https://github.com/kebasyaty/ramifice
|
6
6
|
Project-URL: Documentation, https://kebasyaty.github.io/ramifice/
|
@@ -453,6 +453,11 @@ collection = await User.collection()
|
|
453
453
|
q_filter = {"email": "John_Smith@gmail.com"}
|
454
454
|
mongo_doc = await User.find_one(q_filter)
|
455
455
|
|
456
|
+
# Create object instance from Mongo document.
|
457
|
+
q_filter = {"email": "John_Smith@gmail.com"}
|
458
|
+
mongo_doc = await User.find_one(q_filter)
|
459
|
+
user = User.from_mongo_doc(mongo_doc)
|
460
|
+
|
456
461
|
# Find a single document and converting to raw document.
|
457
462
|
q_filter = {"email": "John_Smith@gmail.com"}
|
458
463
|
raw_doc = await User.find_one_to_raw_doc(q_filter)
|
@@ -516,7 +521,7 @@ async for index in await User.list_indexes():
|
|
516
521
|
# Units Management.
|
517
522
|
# Management for `choices` parameter in dynamic field types.
|
518
523
|
# Units are stored in a separate collection.
|
519
|
-
from ramifice
|
524
|
+
from ramifice import Unit
|
520
525
|
unit = Unit(
|
521
526
|
field="field_name", # The name of the dynamic field.
|
522
527
|
title="Title", # The name of the choice item.
|
@@ -1,11 +1,11 @@
|
|
1
|
-
ramifice/__init__.py,sha256=
|
1
|
+
ramifice/__init__.py,sha256=IuI20h84QWyFftykvte_HLft2iVxwpu0K592NypMwfo,759
|
2
2
|
ramifice/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
ramifice/commons/__init__.py,sha256=FTG78sTU0ay0rvmrq5fUmVjL-I-S7wgQq3BLcyqnjrQ,433
|
4
|
-
ramifice/commons/general.py,sha256=
|
4
|
+
ramifice/commons/general.py,sha256=yi52I9t8R1XePZdyrPmhXJxLc_YkY72Ea7_dBvsKfXI,4984
|
5
5
|
ramifice/commons/indexes.py,sha256=hAcWKZ9MMgLbRtoQ6Af0b8r-PY0dbEYmMBl8z_d1DRo,3646
|
6
6
|
ramifice/commons/many.py,sha256=KGt7licVJmLADvyPtH7-GbXHig-EnGFbnk7QKu3mfvQ,8214
|
7
|
-
ramifice/commons/one.py,sha256=
|
8
|
-
ramifice/commons/tools.py,sha256=
|
7
|
+
ramifice/commons/one.py,sha256=MwUlU9getNtwTOL6-lROdzViBsChWgMIMppCWoeAnFU,5815
|
8
|
+
ramifice/commons/tools.py,sha256=s4CdHb9h8aqR371py0KVsBnNBJSW8-7AVjbTmuFAeeg,1793
|
9
9
|
ramifice/commons/unit_manager.py,sha256=IkWqXu1PHHal0aGfx6zme81iXPeygxPqEWO-u_8RXoI,4356
|
10
10
|
ramifice/fields/__init__.py,sha256=yRfX7Tvpuh27Ggcx5u9e1RRYK7Wu59EVJYxxetmuP1w,1290
|
11
11
|
ramifice/fields/bool_field.py,sha256=WWubSwsFJZu8b3MviDd2zXnNYOQaYw8toklFNSTVFLA,2072
|
@@ -68,9 +68,9 @@ ramifice/paladins/groups/slug_group.py,sha256=joBB5litljbv2h5JKEMzF71s_DKMWH6nzg
|
|
68
68
|
ramifice/paladins/groups/text_group.py,sha256=rUWNaAPkTMMlRf6A-6nQAa4HCj6NBTjPKIYaEKSOUL4,4305
|
69
69
|
ramifice/utils/__init__.py,sha256=xixHoOX4ja5jIUZemem1qn4k4aonv3G3Q76azQK_pkU,43
|
70
70
|
ramifice/utils/errors.py,sha256=iuhq7fzpUmsOyeXeg2fJjta8yAuqlXLKsZVMpfUhtHE,1901
|
71
|
-
ramifice/utils/fixtures.py,sha256=
|
71
|
+
ramifice/utils/fixtures.py,sha256=qsv9cg06lc82XaRlhI1j5vftmOQTTwOcDXCg_lnpK04,3159
|
72
72
|
ramifice/utils/globals.py,sha256=uR20um3Qg_1SG1t7WyWbpq8kQD-9Mslyr_c1yh5Hw9w,1751
|
73
|
-
ramifice/utils/migration.py,sha256=
|
73
|
+
ramifice/utils/migration.py,sha256=JBPDrkox2ONpqfhBVR-i8gHUeyp0cR5if03Ml1rT9Q0,10980
|
74
74
|
ramifice/utils/tools.py,sha256=sOKzwnvf6vdTNf9r6PKAdw6aB4undat2Z8tzS3M1GnQ,2733
|
75
75
|
ramifice/utils/translations.py,sha256=GNGE0ULAA0aOY5pTxUd3MQW-nVaKvp6BeXWEcsR0s0o,4048
|
76
76
|
ramifice/utils/unit.py,sha256=qJ2SpClsFcMRcwB_ZA-QlrB5T9OinCBiWx5KqQ9vH_A,2266
|
@@ -79,7 +79,7 @@ ramifice/utils/mixins/add_valid.py,sha256=TLOObedzXNA9eCylfAVbVCqIKE5sV-P5AdIN7a
|
|
79
79
|
ramifice/utils/mixins/hooks.py,sha256=33jvJRhfnJeL2Hd_YFXk3M_7wjqHaByU2wRjKyboL6s,914
|
80
80
|
ramifice/utils/mixins/indexing.py,sha256=Z0427HoaVRyNmSNN8Fx0mSICgAKV-gDdu3iR5qYUEbs,329
|
81
81
|
ramifice/utils/mixins/json_converter.py,sha256=WhigXyDAV-FfILaZuwvRFRIk0D90Rv3dG5t-mv5fVyc,1107
|
82
|
-
ramifice-0.4.
|
83
|
-
ramifice-0.4.
|
84
|
-
ramifice-0.4.
|
85
|
-
ramifice-0.4.
|
82
|
+
ramifice-0.4.9.dist-info/METADATA,sha256=nSJxqklFILcOWassjetiISC2chZ18V7dlbffS-HAcgo,21785
|
83
|
+
ramifice-0.4.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
84
|
+
ramifice-0.4.9.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
|
85
|
+
ramifice-0.4.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|