ramifice 0.3.27__py3-none-any.whl → 0.3.29__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 +2 -1
- ramifice/commons/__init__.py +1 -3
- ramifice/commons/general.py +9 -9
- ramifice/commons/indexes.py +7 -7
- ramifice/commons/many.py +19 -15
- ramifice/commons/one.py +23 -13
- ramifice/commons/tools.py +62 -57
- ramifice/commons/{units.py → unit_manager.py} +5 -7
- ramifice/fields/bool_field.py +3 -3
- ramifice/fields/choice_float_dyn_field.py +3 -3
- ramifice/fields/choice_float_field.py +3 -3
- ramifice/fields/choice_float_mult_dyn_field.py +3 -3
- ramifice/fields/choice_float_mult_field.py +3 -3
- ramifice/fields/choice_int_dyn_field.py +3 -3
- ramifice/fields/choice_int_field.py +3 -3
- ramifice/fields/choice_int_mult_dyn_field.py +3 -3
- ramifice/fields/choice_int_mult_field.py +3 -3
- ramifice/fields/choice_text_dyn_field.py +3 -3
- ramifice/fields/choice_text_field.py +3 -3
- ramifice/fields/choice_text_mult_dyn_field.py +3 -3
- ramifice/fields/choice_text_mult_field.py +3 -3
- ramifice/fields/color_field.py +4 -4
- ramifice/fields/date_field.py +2 -2
- ramifice/fields/date_time_field.py +2 -2
- ramifice/fields/email_field.py +3 -3
- ramifice/fields/file_field.py +4 -4
- ramifice/fields/float_field.py +3 -3
- ramifice/fields/id_field.py +2 -2
- ramifice/fields/image_field.py +4 -4
- ramifice/fields/integer_field.py +3 -3
- ramifice/fields/ip_field.py +3 -3
- ramifice/fields/password_field.py +2 -2
- ramifice/fields/phone_field.py +3 -3
- ramifice/fields/slug_field.py +3 -3
- ramifice/fields/text_field.py +3 -3
- ramifice/fields/url_field.py +3 -3
- ramifice/models/__init__.py +1 -0
- ramifice/{decorators.py → models/decorator.py} +11 -13
- ramifice/{model.py → models/model.py} +4 -4
- ramifice/{pseudo_model.py → models/pseudo.py} +4 -4
- ramifice/paladins/check.py +11 -11
- ramifice/paladins/delete.py +10 -10
- ramifice/paladins/groups/choice_group.py +1 -1
- ramifice/paladins/groups/date_group.py +1 -1
- ramifice/paladins/groups/file_group.py +2 -2
- ramifice/paladins/groups/id_group.py +1 -1
- ramifice/paladins/groups/img_group.py +2 -2
- ramifice/paladins/groups/num_group.py +1 -1
- ramifice/paladins/groups/pass_group.py +2 -2
- ramifice/paladins/groups/slug_group.py +1 -1
- ramifice/paladins/groups/text_group.py +3 -3
- ramifice/paladins/password.py +10 -10
- ramifice/paladins/refrash.py +7 -7
- ramifice/paladins/save.py +16 -16
- ramifice/paladins/tools.py +1 -1
- ramifice/paladins/validation.py +4 -4
- ramifice/utils/__init__.py +1 -0
- ramifice/{store.py → utils/globals.py} +2 -4
- ramifice/{migration.py → utils/migration.py} +17 -17
- ramifice/utils/mixins/__init__.py +6 -0
- ramifice/{add_valid.py → utils/mixins/add_valid.py} +2 -2
- ramifice/{hooks.py → utils/mixins/hooks.py} +2 -2
- ramifice/utils/mixins/indexing.py +11 -0
- ramifice/{mixins.py → utils/mixins/json_converter.py} +2 -5
- ramifice/{tools.py → utils/tools.py} +1 -1
- ramifice/{types.py → utils/unit.py} +2 -9
- {ramifice-0.3.27.dist-info → ramifice-0.3.29.dist-info}/METADATA +5 -6
- ramifice-0.3.29.dist-info/RECORD +85 -0
- ramifice/indexing.py +0 -11
- ramifice-0.3.27.dist-info/RECORD +0 -82
- /ramifice/{errors.py → utils/errors.py} +0 -0
- /ramifice/{fixtures.py → utils/fixtures.py} +0 -0
- /ramifice/{translations.py → utils/translations.py} +0 -0
- {ramifice-0.3.27.dist-info → ramifice-0.3.29.dist-info}/WHEEL +0 -0
- {ramifice-0.3.27.dist-info → ramifice-0.3.29.dist-info}/licenses/LICENSE +0 -0
ramifice/__init__.py
CHANGED
ramifice/commons/__init__.py
CHANGED
@@ -4,12 +4,10 @@ from .general import GeneralMixin
|
|
4
4
|
from .indexes import IndexMixin
|
5
5
|
from .many import ManyMixin
|
6
6
|
from .one import OneMixin
|
7
|
-
from .
|
8
|
-
from .units import UnitMixin
|
7
|
+
from .unit_manager import UnitMixin
|
9
8
|
|
10
9
|
|
11
10
|
class QCommonsMixin(
|
12
|
-
ToolMixin,
|
13
11
|
GeneralMixin,
|
14
12
|
OneMixin,
|
15
13
|
ManyMixin,
|
ramifice/commons/general.py
CHANGED
@@ -6,7 +6,7 @@ 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 .. import
|
9
|
+
from ..utils import globals
|
10
10
|
|
11
11
|
|
12
12
|
class GeneralMixin:
|
@@ -20,7 +20,7 @@ class GeneralMixin:
|
|
20
20
|
) -> int:
|
21
21
|
"""Gets an estimate of the count of documents in a collection using collection metadata."""
|
22
22
|
# Get collection for current model.
|
23
|
-
collection: AsyncCollection =
|
23
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
24
24
|
#
|
25
25
|
return await collection.estimated_document_count(
|
26
26
|
comment=comment,
|
@@ -37,7 +37,7 @@ class GeneralMixin:
|
|
37
37
|
) -> int:
|
38
38
|
"""Gets an estimate of the count of documents in a collection using collection metadata."""
|
39
39
|
# Get collection for current model.
|
40
|
-
collection: AsyncCollection =
|
40
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
41
41
|
#
|
42
42
|
return await collection.count_documents(
|
43
43
|
filter=filter,
|
@@ -57,7 +57,7 @@ class GeneralMixin:
|
|
57
57
|
) -> AsyncCommandCursor:
|
58
58
|
"""Runs an aggregation framework pipeline."""
|
59
59
|
# Get collection for current model.
|
60
|
-
collection: AsyncCollection =
|
60
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
61
61
|
#
|
62
62
|
return await collection.aggregate(
|
63
63
|
pipeline=pipeline,
|
@@ -82,7 +82,7 @@ class GeneralMixin:
|
|
82
82
|
Returns an array of unique values for specified field of collection.
|
83
83
|
"""
|
84
84
|
# Get collection for current model.
|
85
|
-
collection: AsyncCollection =
|
85
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
86
86
|
#
|
87
87
|
return await collection.distinct(
|
88
88
|
key=key,
|
@@ -97,7 +97,7 @@ class GeneralMixin:
|
|
97
97
|
def collection_name(cls) -> str:
|
98
98
|
"""Get collection name."""
|
99
99
|
# Get collection for current model.
|
100
|
-
collection: AsyncCollection =
|
100
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
101
101
|
#
|
102
102
|
return collection.name
|
103
103
|
|
@@ -108,7 +108,7 @@ class GeneralMixin:
|
|
108
108
|
The full name is of the form database_name.collection_name.
|
109
109
|
"""
|
110
110
|
# Get collection for current model.
|
111
|
-
collection: AsyncCollection =
|
111
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
112
112
|
#
|
113
113
|
return collection.full_name
|
114
114
|
|
@@ -116,7 +116,7 @@ class GeneralMixin:
|
|
116
116
|
def database(cls) -> AsyncDatabase:
|
117
117
|
"""Get AsyncBatabase for the current Model."""
|
118
118
|
# Get collection for current model.
|
119
|
-
collection: AsyncCollection =
|
119
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
120
120
|
#
|
121
121
|
return collection.database
|
122
122
|
|
@@ -124,6 +124,6 @@ class GeneralMixin:
|
|
124
124
|
def collection(cls) -> AsyncCollection:
|
125
125
|
"""Get AsyncCollection for the current Model."""
|
126
126
|
# Get collection for current model.
|
127
|
-
collection: AsyncCollection =
|
127
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
128
128
|
#
|
129
129
|
return collection
|
ramifice/commons/indexes.py
CHANGED
@@ -4,7 +4,7 @@ from typing import Any
|
|
4
4
|
|
5
5
|
from pymongo.asynchronous.collection import AsyncCollection
|
6
6
|
|
7
|
-
from .. import
|
7
|
+
from ..utils import globals
|
8
8
|
|
9
9
|
|
10
10
|
class IndexMixin:
|
@@ -20,7 +20,7 @@ class IndexMixin:
|
|
20
20
|
) -> str:
|
21
21
|
"""Creates an index on this collection."""
|
22
22
|
# Get collection for current model.
|
23
|
-
collection: AsyncCollection =
|
23
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
24
24
|
# Create index.
|
25
25
|
result: str = await collection.create_index(
|
26
26
|
keys=keys,
|
@@ -40,7 +40,7 @@ class IndexMixin:
|
|
40
40
|
) -> None:
|
41
41
|
"""Drops the specified index on this collection."""
|
42
42
|
# Get collection for current model.
|
43
|
-
collection: AsyncCollection =
|
43
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
44
44
|
# Delete index.
|
45
45
|
await collection.drop_index(
|
46
46
|
index_or_name=index_or_name,
|
@@ -59,7 +59,7 @@ class IndexMixin:
|
|
59
59
|
) -> list[str]:
|
60
60
|
"""Create one or more indexes on this collection."""
|
61
61
|
# Get collection for current model.
|
62
|
-
collection: AsyncCollection =
|
62
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
63
63
|
# Create indexes.
|
64
64
|
result: list[str] = await collection.create_indexes(
|
65
65
|
indexes=indexes,
|
@@ -78,7 +78,7 @@ class IndexMixin:
|
|
78
78
|
) -> None:
|
79
79
|
"""Drops all indexes on this collection."""
|
80
80
|
# Get collection for current model.
|
81
|
-
collection: AsyncCollection =
|
81
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
82
82
|
# Delete indexes.
|
83
83
|
await collection.drop_indexes(session=session, comment=comment, **kwargs)
|
84
84
|
|
@@ -90,7 +90,7 @@ class IndexMixin:
|
|
90
90
|
) -> Any:
|
91
91
|
"""Get information on this collection’s indexes."""
|
92
92
|
# Get collection for current model.
|
93
|
-
collection: AsyncCollection =
|
93
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
94
94
|
# Get information.
|
95
95
|
result = await collection.index_information(session=session, comment=comment)
|
96
96
|
return result
|
@@ -103,7 +103,7 @@ class IndexMixin:
|
|
103
103
|
) -> Any:
|
104
104
|
"""Get a cursor over the index documents for this collection."""
|
105
105
|
# Get collection for current model.
|
106
|
-
collection: AsyncCollection =
|
106
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
107
107
|
# Get cursor.
|
108
108
|
cursor = await collection.list_indexes(session=session, comment=comment)
|
109
109
|
return cursor
|
ramifice/commons/many.py
CHANGED
@@ -4,11 +4,12 @@ import json
|
|
4
4
|
from typing import Any
|
5
5
|
|
6
6
|
from pymongo.asynchronous.collection import AsyncCollection
|
7
|
-
from pymongo.asynchronous.cursor import AsyncCursor, CursorType
|
7
|
+
from pymongo.asynchronous.cursor import AsyncCursor, CursorType
|
8
8
|
from pymongo.results import DeleteResult
|
9
9
|
|
10
|
-
from .. import
|
11
|
-
from ..errors import PanicError
|
10
|
+
from ..utils import globals
|
11
|
+
from ..utils.errors import PanicError
|
12
|
+
from .tools import mongo_doc_to_raw_doc, password_to_none
|
12
13
|
|
13
14
|
|
14
15
|
class ManyMixin:
|
@@ -41,14 +42,14 @@ class ManyMixin:
|
|
41
42
|
) -> list[dict[str, Any]]:
|
42
43
|
"""Find documents."""
|
43
44
|
# Get collection for current model.
|
44
|
-
collection: AsyncCollection =
|
45
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
45
46
|
# Get documents.
|
46
47
|
doc_list: list[dict[str, Any]] = []
|
47
48
|
cursor: AsyncCursor = collection.find(
|
48
49
|
filter=filter,
|
49
50
|
projection=projection,
|
50
51
|
skip=skip,
|
51
|
-
limit=limit or cls.META["db_query_docs_limit"],
|
52
|
+
limit=limit or cls.META["db_query_docs_limit"],
|
52
53
|
no_cursor_timeout=no_cursor_timeout,
|
53
54
|
cursor_type=cursor_type,
|
54
55
|
sort=sort,
|
@@ -67,8 +68,9 @@ class ManyMixin:
|
|
67
68
|
session=session,
|
68
69
|
allow_disk_use=allow_disk_use,
|
69
70
|
)
|
71
|
+
field_name_and_type = cls.META["field_name_and_type"]
|
70
72
|
async for mongo_doc in cursor:
|
71
|
-
doc_list.append(
|
73
|
+
doc_list.append(password_to_none(field_name_and_type, mongo_doc))
|
72
74
|
return doc_list
|
73
75
|
|
74
76
|
@classmethod
|
@@ -105,14 +107,14 @@ class ManyMixin:
|
|
105
107
|
datetime to str
|
106
108
|
"""
|
107
109
|
# Get collection for current model.
|
108
|
-
collection: AsyncCollection =
|
110
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
109
111
|
# Get documents.
|
110
112
|
doc_list: list[dict[str, Any]] = []
|
111
113
|
cursor: AsyncCursor = collection.find(
|
112
114
|
filter=filter,
|
113
115
|
projection=projection,
|
114
116
|
skip=skip,
|
115
|
-
limit=limit or cls.META["db_query_docs_limit"],
|
117
|
+
limit=limit or cls.META["db_query_docs_limit"],
|
116
118
|
no_cursor_timeout=no_cursor_timeout,
|
117
119
|
cursor_type=cursor_type,
|
118
120
|
sort=sort,
|
@@ -131,8 +133,9 @@ class ManyMixin:
|
|
131
133
|
session=session,
|
132
134
|
allow_disk_use=allow_disk_use,
|
133
135
|
)
|
136
|
+
field_name_and_type = cls.META["field_name_and_type"]
|
134
137
|
async for mongo_doc in cursor:
|
135
|
-
doc_list.append(
|
138
|
+
doc_list.append(mongo_doc_to_raw_doc(field_name_and_type, mongo_doc))
|
136
139
|
return doc_list
|
137
140
|
|
138
141
|
@classmethod
|
@@ -162,14 +165,14 @@ class ManyMixin:
|
|
162
165
|
) -> str | None:
|
163
166
|
"""Find documents and convert to a json string."""
|
164
167
|
# Get collection for current model.
|
165
|
-
collection: AsyncCollection =
|
168
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
166
169
|
# Get documents.
|
167
170
|
doc_list: list[dict[str, Any]] = []
|
168
171
|
cursor: AsyncCursor = collection.find(
|
169
172
|
filter=filter,
|
170
173
|
projection=projection,
|
171
174
|
skip=skip,
|
172
|
-
limit=limit or cls.META["db_query_docs_limit"],
|
175
|
+
limit=limit or cls.META["db_query_docs_limit"],
|
173
176
|
no_cursor_timeout=no_cursor_timeout,
|
174
177
|
cursor_type=cursor_type,
|
175
178
|
sort=sort,
|
@@ -188,8 +191,9 @@ class ManyMixin:
|
|
188
191
|
session=session,
|
189
192
|
allow_disk_use=allow_disk_use,
|
190
193
|
)
|
194
|
+
field_name_and_type = cls.META["field_name_and_type"]
|
191
195
|
async for mongo_doc in cursor:
|
192
|
-
doc_list.append(
|
196
|
+
doc_list.append(mongo_doc_to_raw_doc(field_name_and_type, mongo_doc))
|
193
197
|
return json.dumps(doc_list) if len(doc_list) > 0 else None
|
194
198
|
|
195
199
|
@classmethod
|
@@ -204,15 +208,15 @@ class ManyMixin:
|
|
204
208
|
) -> DeleteResult:
|
205
209
|
"""Find documents matching with Model."""
|
206
210
|
# Raises a panic if the Model cannot be removed.
|
207
|
-
if not cls.META["is_delete_doc"]:
|
211
|
+
if not cls.META["is_delete_doc"]:
|
208
212
|
msg = (
|
209
|
-
f"Model: `{cls.META['full_model_name']}` > "
|
213
|
+
f"Model: `{cls.META['full_model_name']}` > "
|
210
214
|
+ "META param: `is_delete_doc` (False) => "
|
211
215
|
+ "Documents of this Model cannot be removed from the database!"
|
212
216
|
)
|
213
217
|
raise PanicError(msg)
|
214
218
|
# Get collection for current model.
|
215
|
-
collection: AsyncCollection =
|
219
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
216
220
|
# Delete documents.
|
217
221
|
result: DeleteResult = await collection.delete_many(
|
218
222
|
filter=filter,
|
ramifice/commons/one.py
CHANGED
@@ -5,8 +5,9 @@ from typing import Any
|
|
5
5
|
from pymongo.asynchronous.collection import AsyncCollection
|
6
6
|
from pymongo.results import DeleteResult
|
7
7
|
|
8
|
-
from .. import
|
9
|
-
from ..errors import PanicError
|
8
|
+
from ..utils import globals
|
9
|
+
from ..utils.errors import PanicError
|
10
|
+
from .tools import from_mongo_doc, mongo_doc_to_raw_doc, password_to_none
|
10
11
|
|
11
12
|
|
12
13
|
class OneMixin:
|
@@ -21,11 +22,14 @@ class OneMixin:
|
|
21
22
|
) -> dict[str, Any] | None:
|
22
23
|
"""Find a single document."""
|
23
24
|
# Get collection for current model.
|
24
|
-
collection: AsyncCollection =
|
25
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
25
26
|
# Get document.
|
26
27
|
mongo_doc = await collection.find_one(filter, *args, **kwargs)
|
27
28
|
if mongo_doc is not None:
|
28
|
-
mongo_doc =
|
29
|
+
mongo_doc = password_to_none(
|
30
|
+
cls.META["field_name_and_type"],
|
31
|
+
mongo_doc,
|
32
|
+
)
|
29
33
|
return mongo_doc
|
30
34
|
|
31
35
|
@classmethod
|
@@ -37,12 +41,15 @@ class OneMixin:
|
|
37
41
|
) -> dict[str, Any] | None:
|
38
42
|
"""Find a single document and converting to raw document."""
|
39
43
|
# Get collection for current model.
|
40
|
-
collection: AsyncCollection =
|
44
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
41
45
|
# Get document.
|
42
46
|
raw_doc = None
|
43
47
|
mongo_doc = await collection.find_one(filter, *args, **kwargs)
|
44
48
|
if mongo_doc is not None:
|
45
|
-
raw_doc =
|
49
|
+
raw_doc = mongo_doc_to_raw_doc(
|
50
|
+
cls.META["field_name_and_type"],
|
51
|
+
mongo_doc,
|
52
|
+
)
|
46
53
|
return raw_doc
|
47
54
|
|
48
55
|
@classmethod
|
@@ -54,13 +61,13 @@ class OneMixin:
|
|
54
61
|
) -> Any | None:
|
55
62
|
"""Find a single document and convert it to a Model instance."""
|
56
63
|
# Get collection for current model.
|
57
|
-
collection: AsyncCollection =
|
64
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
58
65
|
# Get document.
|
59
66
|
inst_model = None
|
60
67
|
mongo_doc = await collection.find_one(filter, *args, **kwargs)
|
61
68
|
if mongo_doc is not None:
|
62
69
|
# Convert document to Model instance.
|
63
|
-
inst_model =
|
70
|
+
inst_model = from_mongo_doc(cls, mongo_doc)
|
64
71
|
return inst_model
|
65
72
|
|
66
73
|
@classmethod
|
@@ -72,13 +79,13 @@ class OneMixin:
|
|
72
79
|
) -> str | None:
|
73
80
|
"""Find a single document and convert it to a JSON string."""
|
74
81
|
# Get collection for current model.
|
75
|
-
collection: AsyncCollection =
|
82
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
76
83
|
# Get document.
|
77
84
|
json_str: str | None = None
|
78
85
|
mongo_doc = await collection.find_one(filter, *args, **kwargs)
|
79
86
|
if mongo_doc is not None:
|
80
87
|
# Convert document to Model instance.
|
81
|
-
inst_model =
|
88
|
+
inst_model = from_mongo_doc(cls, mongo_doc)
|
82
89
|
json_str = inst_model.to_json()
|
83
90
|
return json_str
|
84
91
|
|
@@ -102,7 +109,7 @@ class OneMixin:
|
|
102
109
|
)
|
103
110
|
raise PanicError(msg)
|
104
111
|
# Get collection for current model.
|
105
|
-
collection: AsyncCollection =
|
112
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
106
113
|
# Get document.
|
107
114
|
result: DeleteResult = await collection.delete_one(
|
108
115
|
filter=filter,
|
@@ -136,7 +143,7 @@ class OneMixin:
|
|
136
143
|
)
|
137
144
|
raise PanicError(msg)
|
138
145
|
# Get collection for current model.
|
139
|
-
collection: AsyncCollection =
|
146
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
140
147
|
# Get document.
|
141
148
|
mongo_doc: dict[str, Any] | None = await collection.find_one_and_delete(
|
142
149
|
filter=filter,
|
@@ -149,5 +156,8 @@ class OneMixin:
|
|
149
156
|
**kwargs,
|
150
157
|
)
|
151
158
|
if mongo_doc is not None:
|
152
|
-
mongo_doc =
|
159
|
+
mongo_doc = password_to_none(
|
160
|
+
cls.META["field_name_and_type"],
|
161
|
+
mongo_doc,
|
162
|
+
)
|
153
163
|
return mongo_doc
|
ramifice/commons/tools.py
CHANGED
@@ -4,60 +4,65 @@ from typing import Any
|
|
4
4
|
|
5
5
|
from babel.dates import format_date, format_datetime
|
6
6
|
|
7
|
-
from .. import translations
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
value
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
7
|
+
from ..utils import translations
|
8
|
+
|
9
|
+
|
10
|
+
def password_to_none(
|
11
|
+
field_name_and_type: dict[str, str],
|
12
|
+
mongo_doc: dict[str, Any],
|
13
|
+
) -> dict[str, Any]:
|
14
|
+
"""Create object instance from Mongo document."""
|
15
|
+
for f_name, t_name in field_name_and_type.items():
|
16
|
+
if "Pass" in t_name:
|
17
|
+
mongo_doc[f_name] = None
|
18
|
+
return mongo_doc
|
19
|
+
|
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 = cls_model()
|
27
|
+
for name, data in mongo_doc.items():
|
28
|
+
field = obj.__dict__[name]
|
29
|
+
field.value = data if field.group != "pass" else None
|
30
|
+
return obj
|
31
|
+
|
32
|
+
|
33
|
+
def mongo_doc_to_raw_doc(
|
34
|
+
field_name_and_type: dict[str, str],
|
35
|
+
mongo_doc: dict[str, Any],
|
36
|
+
) -> dict[str, Any]:
|
37
|
+
"""Convert the Mongo document to the raw document.
|
38
|
+
|
39
|
+
Special changes:
|
40
|
+
_id to str
|
41
|
+
password to None
|
42
|
+
date to str
|
43
|
+
datetime to str
|
44
|
+
"""
|
45
|
+
doc: dict[str, Any] = {}
|
46
|
+
current_locale = translations.CURRENT_LOCALE
|
47
|
+
for f_name, t_name in field_name_and_type.items():
|
48
|
+
value = mongo_doc[f_name]
|
49
|
+
if value is not None:
|
50
|
+
if "Date" in t_name:
|
51
|
+
if "Time" in t_name:
|
52
|
+
value = format_datetime(
|
53
|
+
datetime=value,
|
54
|
+
format="short",
|
55
|
+
locale=current_locale,
|
56
|
+
)
|
57
|
+
else:
|
58
|
+
value = format_date(
|
59
|
+
date=value.date(),
|
60
|
+
format="short",
|
61
|
+
locale=current_locale,
|
62
|
+
)
|
63
|
+
elif "ID" in t_name:
|
64
|
+
value = str(value)
|
65
|
+
elif "Pass" in t_name:
|
66
|
+
value = None
|
67
|
+
doc[f_name] = value
|
68
|
+
return doc
|
@@ -7,9 +7,9 @@ from typing import Any
|
|
7
7
|
|
8
8
|
from pymongo.asynchronous.collection import AsyncCollection
|
9
9
|
|
10
|
-
from .. import
|
11
|
-
from ..errors import PanicError
|
12
|
-
from ..
|
10
|
+
from ..utils import globals
|
11
|
+
from ..utils.errors import PanicError
|
12
|
+
from ..utils.unit import Unit
|
13
13
|
|
14
14
|
|
15
15
|
class UnitMixin:
|
@@ -26,9 +26,7 @@ class UnitMixin:
|
|
26
26
|
"""
|
27
27
|
# Get access to super collection.
|
28
28
|
# (Contains Model state and dynamic field data.)
|
29
|
-
super_collection: AsyncCollection =
|
30
|
-
store.SUPER_COLLECTION_NAME
|
31
|
-
]
|
29
|
+
super_collection: AsyncCollection = globals.MONGO_DATABASE[globals.SUPER_COLLECTION_NAME]
|
32
30
|
# Get Model state.
|
33
31
|
model_state: dict[str, Any] | None = await super_collection.find_one(
|
34
32
|
filter={"collection_name": cls.META["collection_name"]}
|
@@ -89,7 +87,7 @@ class UnitMixin:
|
|
89
87
|
if unit.is_delete:
|
90
88
|
unit_field: str = unit.field
|
91
89
|
unit_value: float | int | str = unit.value
|
92
|
-
collection: AsyncCollection =
|
90
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls.META["collection_name"]]
|
93
91
|
async for mongo_doc in collection.find():
|
94
92
|
field_value = mongo_doc[unit_field]
|
95
93
|
if field_value is not None:
|
ramifice/fields/bool_field.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
"""Field of Model for enter boolean value."""
|
2
2
|
|
3
|
-
from .. import
|
4
|
-
from ..mixins import JsonMixin
|
3
|
+
from ..utils import globals
|
4
|
+
from ..utils.mixins.json_converter import JsonMixin
|
5
5
|
from .general.field import Field
|
6
6
|
|
7
7
|
|
@@ -18,7 +18,7 @@ class BooleanField(Field, JsonMixin):
|
|
18
18
|
warning: list[str] | None = None,
|
19
19
|
default: bool = False,
|
20
20
|
):
|
21
|
-
if
|
21
|
+
if globals.DEBUG:
|
22
22
|
if default is not None and not isinstance(default, bool):
|
23
23
|
raise AssertionError("Parameter `default` - Not а `bool` type!")
|
24
24
|
if not isinstance(label, str):
|
@@ -3,8 +3,8 @@
|
|
3
3
|
Type of selective float field with dynamic addition of elements.
|
4
4
|
"""
|
5
5
|
|
6
|
-
from .. import
|
7
|
-
from ..mixins import JsonMixin
|
6
|
+
from ..utils import globals
|
7
|
+
from ..utils.mixins.json_converter import JsonMixin
|
8
8
|
from .general.choice_group import ChoiceGroup
|
9
9
|
from .general.field import Field
|
10
10
|
|
@@ -28,7 +28,7 @@ class ChoiceFloatDynField(Field, ChoiceGroup, JsonMixin):
|
|
28
28
|
required: bool = False,
|
29
29
|
readonly: bool = False,
|
30
30
|
):
|
31
|
-
if
|
31
|
+
if globals.DEBUG:
|
32
32
|
if not isinstance(label, str):
|
33
33
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
34
34
|
if not isinstance(disabled, bool):
|
@@ -3,8 +3,8 @@
|
|
3
3
|
Type of selective float field with static of elements.
|
4
4
|
"""
|
5
5
|
|
6
|
-
from .. import
|
7
|
-
from ..mixins import JsonMixin
|
6
|
+
from ..utils import globals
|
7
|
+
from ..utils.mixins.json_converter import JsonMixin
|
8
8
|
from .general.choice_group import ChoiceGroup
|
9
9
|
from .general.field import Field
|
10
10
|
|
@@ -51,7 +51,7 @@ class ChoiceFloatField(Field, ChoiceGroup, JsonMixin):
|
|
51
51
|
self.default = default
|
52
52
|
self.choices = choices
|
53
53
|
|
54
|
-
if
|
54
|
+
if globals.DEBUG:
|
55
55
|
if choices is not None and not isinstance(choices, dict):
|
56
56
|
raise AssertionError("Parameter `choices` - Not а `dict` type!")
|
57
57
|
if default is not None and not isinstance(default, float):
|
@@ -3,8 +3,8 @@
|
|
3
3
|
Type of selective float field with dynamic addition of elements.
|
4
4
|
"""
|
5
5
|
|
6
|
-
from .. import
|
7
|
-
from ..mixins import JsonMixin
|
6
|
+
from ..utils import globals
|
7
|
+
from ..utils.mixins.json_converter import JsonMixin
|
8
8
|
from .general.choice_group import ChoiceGroup
|
9
9
|
from .general.field import Field
|
10
10
|
|
@@ -27,7 +27,7 @@ class ChoiceFloatMultDynField(Field, ChoiceGroup, JsonMixin):
|
|
27
27
|
required: bool = False,
|
28
28
|
readonly: bool = False,
|
29
29
|
):
|
30
|
-
if
|
30
|
+
if globals.DEBUG:
|
31
31
|
if not isinstance(label, str):
|
32
32
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
33
33
|
if not isinstance(disabled, bool):
|
@@ -3,8 +3,8 @@
|
|
3
3
|
Type of selective float field with static of elements.
|
4
4
|
"""
|
5
5
|
|
6
|
-
from .. import
|
7
|
-
from ..mixins import JsonMixin
|
6
|
+
from ..utils import globals
|
7
|
+
from ..utils.mixins.json_converter import JsonMixin
|
8
8
|
from .general.choice_group import ChoiceGroup
|
9
9
|
from .general.field import Field
|
10
10
|
|
@@ -52,7 +52,7 @@ class ChoiceFloatMultField(Field, ChoiceGroup, JsonMixin):
|
|
52
52
|
self.default = default
|
53
53
|
self.choices = choices
|
54
54
|
|
55
|
-
if
|
55
|
+
if globals.DEBUG:
|
56
56
|
if choices is not None:
|
57
57
|
if not isinstance(choices, dict):
|
58
58
|
raise AssertionError("Parameter `choices` - Not а `dict` type!")
|