ramifice 0.3.28__py3-none-any.whl → 0.3.30__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/general.py +9 -9
- ramifice/commons/indexes.py +7 -7
- ramifice/commons/many.py +14 -14
- ramifice/commons/one.py +7 -7
- ramifice/commons/unit_manager.py +3 -5
- ramifice/fields/bool_field.py +2 -2
- ramifice/fields/choice_float_dyn_field.py +2 -2
- ramifice/fields/choice_float_field.py +2 -2
- ramifice/fields/choice_float_mult_dyn_field.py +2 -2
- ramifice/fields/choice_float_mult_field.py +2 -2
- ramifice/fields/choice_int_dyn_field.py +2 -2
- ramifice/fields/choice_int_field.py +2 -2
- ramifice/fields/choice_int_mult_dyn_field.py +2 -2
- ramifice/fields/choice_int_mult_field.py +2 -2
- ramifice/fields/choice_text_dyn_field.py +2 -2
- ramifice/fields/choice_text_field.py +2 -2
- ramifice/fields/choice_text_mult_dyn_field.py +2 -2
- ramifice/fields/choice_text_mult_field.py +2 -2
- ramifice/fields/color_field.py +3 -3
- ramifice/fields/date_field.py +2 -2
- ramifice/fields/date_time_field.py +2 -2
- ramifice/fields/email_field.py +2 -2
- ramifice/fields/file_field.py +2 -2
- ramifice/fields/float_field.py +2 -2
- ramifice/fields/id_field.py +2 -2
- ramifice/fields/image_field.py +2 -2
- ramifice/fields/integer_field.py +2 -2
- ramifice/fields/ip_field.py +2 -2
- ramifice/fields/password_field.py +2 -2
- ramifice/fields/phone_field.py +2 -2
- ramifice/fields/slug_field.py +2 -2
- ramifice/fields/text_field.py +2 -2
- ramifice/fields/url_field.py +2 -2
- ramifice/models/decorator.py +3 -3
- ramifice/models/model.py +1 -1
- ramifice/paladins/check.py +10 -10
- ramifice/paladins/delete.py +9 -9
- ramifice/paladins/groups/text_group.py +1 -1
- ramifice/paladins/password.py +9 -9
- ramifice/paladins/refrash.py +6 -6
- ramifice/paladins/save.py +15 -15
- ramifice/paladins/validation.py +4 -4
- ramifice/utils/{store.py → globals.py} +2 -4
- ramifice/utils/migration.py +16 -16
- ramifice/utils/tools.py +1 -1
- {ramifice-0.3.28.dist-info → ramifice-0.3.30.dist-info}/METADATA +1 -1
- ramifice-0.3.30.dist-info/RECORD +85 -0
- ramifice-0.3.28.dist-info/RECORD +0 -85
- {ramifice-0.3.28.dist-info → ramifice-0.3.30.dist-info}/WHEEL +0 -0
- {ramifice-0.3.28.dist-info → ramifice-0.3.30.dist-info}/licenses/LICENSE +0 -0
ramifice/fields/email_field.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from email_validator import EmailNotValidError, validate_email
|
4
4
|
|
5
|
-
from ..utils import
|
5
|
+
from ..utils import globals
|
6
6
|
from ..utils.mixins.json_converter import JsonMixin
|
7
7
|
from .general.field import Field
|
8
8
|
from .general.text_group import TextGroup
|
@@ -25,7 +25,7 @@ class EmailField(Field, TextGroup, JsonMixin):
|
|
25
25
|
readonly: bool = False,
|
26
26
|
unique: bool = False,
|
27
27
|
):
|
28
|
-
if
|
28
|
+
if globals.DEBUG:
|
29
29
|
if default is not None:
|
30
30
|
if not isinstance(default, str):
|
31
31
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/file_field.py
CHANGED
@@ -8,7 +8,7 @@ from datetime import date
|
|
8
8
|
from pathlib import Path
|
9
9
|
from typing import Any
|
10
10
|
|
11
|
-
from ..utils import
|
11
|
+
from ..utils import globals
|
12
12
|
from ..utils.errors import FileHasNoExtensionError
|
13
13
|
from ..utils.mixins.json_converter import JsonMixin
|
14
14
|
from .general.field import Field
|
@@ -34,7 +34,7 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
34
34
|
target_dir: str = "files",
|
35
35
|
accept: str = "",
|
36
36
|
):
|
37
|
-
if
|
37
|
+
if globals.DEBUG:
|
38
38
|
if default is not None:
|
39
39
|
if not isinstance(default, str):
|
40
40
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/float_field.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""Field of Model for enter (float) number."""
|
2
2
|
|
3
|
-
from ..utils import
|
3
|
+
from ..utils import globals
|
4
4
|
from ..utils.mixins.json_converter import JsonMixin
|
5
5
|
from .general.field import Field
|
6
6
|
from .general.number_group import NumberGroup
|
@@ -27,7 +27,7 @@ class FloatField(Field, NumberGroup, JsonMixin):
|
|
27
27
|
step: float = 1.0,
|
28
28
|
input_type: str = "number", # number | range
|
29
29
|
):
|
30
|
-
if
|
30
|
+
if globals.DEBUG:
|
31
31
|
if input_type not in ["number", "range"]:
|
32
32
|
raise AssertionError(
|
33
33
|
"Parameter `input_type` - Invalid input type! "
|
ramifice/fields/id_field.py
CHANGED
@@ -5,7 +5,7 @@ from typing import Any
|
|
5
5
|
|
6
6
|
from bson.objectid import ObjectId
|
7
7
|
|
8
|
-
from ..utils import
|
8
|
+
from ..utils import globals
|
9
9
|
from .general.field import Field
|
10
10
|
|
11
11
|
|
@@ -33,7 +33,7 @@ class IDField(Field):
|
|
33
33
|
readonly: bool = False,
|
34
34
|
unique: bool = False,
|
35
35
|
):
|
36
|
-
if
|
36
|
+
if globals.DEBUG:
|
37
37
|
if not isinstance(label, str):
|
38
38
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
39
39
|
if not isinstance(disabled, bool):
|
ramifice/fields/image_field.py
CHANGED
@@ -10,7 +10,7 @@ from typing import Any
|
|
10
10
|
|
11
11
|
from PIL import Image
|
12
12
|
|
13
|
-
from ..utils import
|
13
|
+
from ..utils import globals
|
14
14
|
from ..utils.errors import FileHasNoExtensionError
|
15
15
|
from ..utils.mixins.json_converter import JsonMixin
|
16
16
|
from .general.field import Field
|
@@ -41,7 +41,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
41
41
|
# True - high quality and low performance for thumbnails.
|
42
42
|
high_quality: bool = False,
|
43
43
|
):
|
44
|
-
if
|
44
|
+
if globals.DEBUG:
|
45
45
|
if default is not None:
|
46
46
|
if not isinstance(default, str):
|
47
47
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/integer_field.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""Field of Model for enter (int) number."""
|
2
2
|
|
3
|
-
from ..utils import
|
3
|
+
from ..utils import globals
|
4
4
|
from ..utils.mixins.json_converter import JsonMixin
|
5
5
|
from .general.field import Field
|
6
6
|
from .general.number_group import NumberGroup
|
@@ -27,7 +27,7 @@ class IntegerField(Field, NumberGroup, JsonMixin):
|
|
27
27
|
step: int = 1,
|
28
28
|
input_type: str = "number", # number | range
|
29
29
|
):
|
30
|
-
if
|
30
|
+
if globals.DEBUG:
|
31
31
|
if input_type not in ["number", "range"]:
|
32
32
|
raise AssertionError(
|
33
33
|
"Parameter `input_type` - Invalid input type! "
|
ramifice/fields/ip_field.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import ipaddress
|
4
4
|
|
5
|
-
from ..utils import
|
5
|
+
from ..utils import globals
|
6
6
|
from ..utils.mixins.json_converter import JsonMixin
|
7
7
|
from .general.field import Field
|
8
8
|
from .general.text_group import TextGroup
|
@@ -25,7 +25,7 @@ class IPField(Field, TextGroup, JsonMixin):
|
|
25
25
|
readonly: bool = False,
|
26
26
|
unique: bool = False,
|
27
27
|
):
|
28
|
-
if
|
28
|
+
if globals.DEBUG:
|
29
29
|
if default is not None:
|
30
30
|
if not isinstance(default, str):
|
31
31
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import json
|
4
4
|
from typing import Any
|
5
5
|
|
6
|
-
from ..utils import
|
6
|
+
from ..utils import globals
|
7
7
|
from .general.field import Field
|
8
8
|
|
9
9
|
|
@@ -26,7 +26,7 @@ class PasswordField(Field):
|
|
26
26
|
placeholder: str = "",
|
27
27
|
required: bool = False,
|
28
28
|
):
|
29
|
-
if
|
29
|
+
if globals.DEBUG:
|
30
30
|
if not isinstance(label, str):
|
31
31
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
32
32
|
if not isinstance(hide, bool):
|
ramifice/fields/phone_field.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
import phonenumbers
|
4
4
|
|
5
|
-
from ..utils import
|
5
|
+
from ..utils import globals
|
6
6
|
from ..utils.mixins.json_converter import JsonMixin
|
7
7
|
from .general.field import Field
|
8
8
|
from .general.text_group import TextGroup
|
@@ -28,7 +28,7 @@ class PhoneField(Field, TextGroup, JsonMixin):
|
|
28
28
|
readonly: bool = False,
|
29
29
|
unique: bool = False,
|
30
30
|
):
|
31
|
-
if
|
31
|
+
if globals.DEBUG:
|
32
32
|
if default is not None:
|
33
33
|
if not isinstance(default, str):
|
34
34
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/slug_field.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""Field of Model for automatic generation of string `slug`."""
|
2
2
|
|
3
|
-
from ..utils import
|
3
|
+
from ..utils import globals
|
4
4
|
from ..utils.mixins.json_converter import JsonMixin
|
5
5
|
from .general.field import Field
|
6
6
|
from .general.text_group import TextGroup
|
@@ -24,7 +24,7 @@ class SlugField(Field, TextGroup, JsonMixin):
|
|
24
24
|
readonly: bool = False,
|
25
25
|
slug_sources: list[str] = ["_id"],
|
26
26
|
):
|
27
|
-
if
|
27
|
+
if globals.DEBUG:
|
28
28
|
if not isinstance(label, str):
|
29
29
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
30
30
|
if not isinstance(disabled, bool):
|
ramifice/fields/text_field.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""Field of Model for enter text."""
|
2
2
|
|
3
|
-
from ..utils import
|
3
|
+
from ..utils import globals
|
4
4
|
from ..utils.mixins.json_converter import JsonMixin
|
5
5
|
from .general.field import Field
|
6
6
|
from .general.text_group import TextGroup
|
@@ -26,7 +26,7 @@ class TextField(Field, TextGroup, JsonMixin):
|
|
26
26
|
unique: bool = False,
|
27
27
|
maxlength: int = 256,
|
28
28
|
):
|
29
|
-
if
|
29
|
+
if globals.DEBUG:
|
30
30
|
if not isinstance(maxlength, int):
|
31
31
|
raise AssertionError("Parameter `maxlength` - Not а `int` type!")
|
32
32
|
if default is not None:
|
ramifice/fields/url_field.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from urllib.parse import urlparse
|
4
4
|
|
5
|
-
from ..utils import
|
5
|
+
from ..utils import globals
|
6
6
|
from ..utils.mixins.json_converter import JsonMixin
|
7
7
|
from .general.field import Field
|
8
8
|
from .general.text_group import TextGroup
|
@@ -39,7 +39,7 @@ class URLField(Field, TextGroup, JsonMixin):
|
|
39
39
|
readonly: bool = False,
|
40
40
|
unique: bool = False,
|
41
41
|
):
|
42
|
-
if
|
42
|
+
if globals.DEBUG:
|
43
43
|
if default is not None:
|
44
44
|
if not isinstance(default, str):
|
45
45
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/models/decorator.py
CHANGED
@@ -4,13 +4,13 @@ import os
|
|
4
4
|
from typing import Any
|
5
5
|
|
6
6
|
from ..commons import QCommonsMixin
|
7
|
-
from ..fields import DateTimeField, IDField
|
8
|
-
from ..paladins import CheckMixin, QPaladinsMixin, ValidationMixin
|
7
|
+
from ..fields import DateTimeField, IDField
|
8
|
+
from ..paladins import CheckMixin, QPaladinsMixin, ValidationMixin
|
9
9
|
from ..utils.errors import DoesNotMatchRegexError, PanicError
|
10
10
|
from ..utils.mixins.add_valid import AddValidMixin
|
11
11
|
from ..utils.mixins.hooks import HooksMixin
|
12
12
|
from ..utils.mixins.indexing import IndexMixin
|
13
|
-
from ..utils.
|
13
|
+
from ..utils.globals import REGEX
|
14
14
|
from .model import Model
|
15
15
|
from .pseudo import PseudoModel
|
16
16
|
|
ramifice/models/model.py
CHANGED
@@ -8,7 +8,7 @@ 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 ..fields import DateTimeField, IDField
|
11
|
+
from ..fields import DateTimeField, IDField
|
12
12
|
from ..utils import translations
|
13
13
|
|
14
14
|
|
ramifice/paladins/check.py
CHANGED
@@ -7,9 +7,9 @@ from typing import Any
|
|
7
7
|
from bson.objectid import ObjectId
|
8
8
|
from pymongo.asynchronous.collection import AsyncCollection
|
9
9
|
|
10
|
-
from ..utils import
|
10
|
+
from ..utils import globals
|
11
11
|
from ..utils.errors import PanicError
|
12
|
-
from .groups import (
|
12
|
+
from .groups import (
|
13
13
|
BoolGroupMixin,
|
14
14
|
ChoiceGroupMixin,
|
15
15
|
DateGroupMixin,
|
@@ -45,11 +45,11 @@ class CheckMixin(
|
|
45
45
|
It is also used to verify Models that do not migrate to the database.
|
46
46
|
"""
|
47
47
|
cls_model = self.__class__
|
48
|
-
is_migrate_model: bool = cls_model.META["is_migrate_model"]
|
48
|
+
is_migrate_model: bool = cls_model.META["is_migrate_model"]
|
49
49
|
|
50
50
|
if not is_migrate_model and is_save:
|
51
51
|
msg = (
|
52
|
-
f"Model: `{self.full_model_name()}` > "
|
52
|
+
f"Model: `{self.full_model_name()}` > "
|
53
53
|
+ "Method: `check` => "
|
54
54
|
+ "For a non -migrating Model, the `is_save` parameter must be equal to` False` !"
|
55
55
|
)
|
@@ -59,20 +59,20 @@ class CheckMixin(
|
|
59
59
|
is_update: bool = False
|
60
60
|
if is_migrate_model:
|
61
61
|
# Get the document ID.
|
62
|
-
doc_id = self._id.value
|
62
|
+
doc_id = self._id.value
|
63
63
|
# Does the document exist in the database?
|
64
64
|
is_update = doc_id is not None
|
65
65
|
# Create an identifier for a new document.
|
66
66
|
if is_save and not is_update:
|
67
67
|
doc_id = ObjectId()
|
68
|
-
self._id.value = doc_id
|
68
|
+
self._id.value = doc_id
|
69
69
|
|
70
70
|
result_map: dict[str, Any] = {}
|
71
71
|
# Errors from additional validation of fields.
|
72
|
-
error_map: dict[str, str] = await self.add_validation() or {}
|
72
|
+
error_map: dict[str, str] = await self.add_validation() or {}
|
73
73
|
# Get Model collection.
|
74
74
|
if collection is None:
|
75
|
-
collection =
|
75
|
+
collection = globals.MONGO_DATABASE[cls_model.META["collection_name"]]
|
76
76
|
# Create params for *_group methods.
|
77
77
|
params: dict[str, Any] = {
|
78
78
|
"doc_id": doc_id,
|
@@ -82,7 +82,7 @@ class CheckMixin(
|
|
82
82
|
"result_map": result_map, # Data to save or update to the database.
|
83
83
|
"collection": collection,
|
84
84
|
"field_data": None,
|
85
|
-
"full_model_name": cls_model.META["full_model_name"],
|
85
|
+
"full_model_name": cls_model.META["full_model_name"],
|
86
86
|
"is_migrate_model": is_migrate_model,
|
87
87
|
}
|
88
88
|
|
@@ -126,7 +126,7 @@ class CheckMixin(
|
|
126
126
|
if params["is_error_symptom"]:
|
127
127
|
# Reset the ObjectId for a new document.
|
128
128
|
if not is_update:
|
129
|
-
self._id.value = None
|
129
|
+
self._id.value = None
|
130
130
|
# Delete orphaned files.
|
131
131
|
curr_doc: dict[str, Any] | None = (
|
132
132
|
await collection.find_one({"_id": doc_id}) if is_update else None
|
ramifice/paladins/delete.py
CHANGED
@@ -6,7 +6,7 @@ from typing import Any
|
|
6
6
|
|
7
7
|
from pymongo.asynchronous.collection import AsyncCollection
|
8
8
|
|
9
|
-
from ..utils import
|
9
|
+
from ..utils import globals
|
10
10
|
from ..utils.errors import PanicError
|
11
11
|
|
12
12
|
|
@@ -27,26 +27,26 @@ class DeleteMixin:
|
|
27
27
|
"""Delete document from database."""
|
28
28
|
cls_model = self.__class__
|
29
29
|
# Raises a panic if the Model cannot be removed.
|
30
|
-
if not cls_model.META["is_delete_doc"]:
|
30
|
+
if not cls_model.META["is_delete_doc"]:
|
31
31
|
msg = (
|
32
|
-
f"Model: `{cls_model.META['full_model_name']}` > "
|
32
|
+
f"Model: `{cls_model.META['full_model_name']}` > "
|
33
33
|
+ "META param: `is_delete_doc` (False) => "
|
34
34
|
+ "Documents of this Model cannot be removed from the database!"
|
35
35
|
)
|
36
36
|
raise PanicError(msg)
|
37
37
|
# Get documet ID.
|
38
|
-
doc_id = self._id.value
|
38
|
+
doc_id = self._id.value
|
39
39
|
if doc_id is None:
|
40
40
|
msg = (
|
41
|
-
f"Model: `{cls_model.META['full_model_name']}` > "
|
41
|
+
f"Model: `{cls_model.META['full_model_name']}` > "
|
42
42
|
+ "Field: `_id` > "
|
43
43
|
+ "Param: `value` => ID is missing."
|
44
44
|
)
|
45
45
|
raise PanicError(msg)
|
46
46
|
# Run hook.
|
47
|
-
await self.pre_delete()
|
47
|
+
await self.pre_delete()
|
48
48
|
# Get collection for current Model.
|
49
|
-
collection: AsyncCollection =
|
49
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls_model.META["collection_name"]]
|
50
50
|
# Delete document.
|
51
51
|
mongo_doc: dict[str, Any] = {}
|
52
52
|
mongo_doc = await collection.find_one_and_delete(
|
@@ -62,7 +62,7 @@ class DeleteMixin:
|
|
62
62
|
# If the document failed to delete.
|
63
63
|
if not bool(mongo_doc):
|
64
64
|
msg = (
|
65
|
-
f"Model: `{cls_model.META['full_model_name']}` > "
|
65
|
+
f"Model: `{cls_model.META['full_model_name']}` > "
|
66
66
|
+ "Method: `delete` => "
|
67
67
|
+ "The document was not deleted, the document is absent in the database."
|
68
68
|
)
|
@@ -86,6 +86,6 @@ class DeleteMixin:
|
|
86
86
|
file_data = None
|
87
87
|
field_data.value = None
|
88
88
|
# Run hook.
|
89
|
-
await self.post_delete()
|
89
|
+
await self.post_delete()
|
90
90
|
#
|
91
91
|
return mongo_doc
|
@@ -53,7 +53,7 @@ class TextGroupMixin:
|
|
53
53
|
try:
|
54
54
|
emailinfo = validate_email(
|
55
55
|
str(value),
|
56
|
-
check_deliverability=self.__class__.META["is_migrate_model"],
|
56
|
+
check_deliverability=self.__class__.META["is_migrate_model"],
|
57
57
|
)
|
58
58
|
value = emailinfo.normalized
|
59
59
|
params["field_data"].value = value
|
ramifice/paladins/password.py
CHANGED
@@ -5,7 +5,7 @@ from typing import Any
|
|
5
5
|
from argon2 import PasswordHasher
|
6
6
|
from pymongo.asynchronous.collection import AsyncCollection
|
7
7
|
|
8
|
-
from ..utils import
|
8
|
+
from ..utils import globals
|
9
9
|
from ..utils.errors import OldPassNotMatchError, PanicError
|
10
10
|
|
11
11
|
|
@@ -20,30 +20,30 @@ class PasswordMixin:
|
|
20
20
|
"""For password verification."""
|
21
21
|
cls_model = self.__class__
|
22
22
|
# Get documet ID.
|
23
|
-
doc_id = self._id.value
|
23
|
+
doc_id = self._id.value
|
24
24
|
if doc_id is None:
|
25
25
|
msg = (
|
26
|
-
f"Model: `{cls_model.META['full_model_name']}` > "
|
26
|
+
f"Model: `{cls_model.META['full_model_name']}` > "
|
27
27
|
+ "Method: `verify_password` => "
|
28
28
|
+ "Cannot get document ID - ID field is empty."
|
29
29
|
)
|
30
30
|
raise PanicError(msg)
|
31
31
|
# Get collection for current Model.
|
32
|
-
collection: AsyncCollection =
|
32
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls_model.META["collection_name"]]
|
33
33
|
# Get document.
|
34
34
|
mongo_doc: dict[str, Any] | None = await collection.find_one({"_id": doc_id})
|
35
35
|
if mongo_doc is None:
|
36
36
|
msg = (
|
37
|
-
f"Model: `{cls_model.META['full_model_name']}` > "
|
37
|
+
f"Model: `{cls_model.META['full_model_name']}` > "
|
38
38
|
+ "Method: `verify_password` => "
|
39
|
-
+ f"There is no document with ID `{self._id.value}` in the database."
|
39
|
+
+ f"There is no document with ID `{self._id.value}` in the database."
|
40
40
|
)
|
41
41
|
raise PanicError(msg)
|
42
42
|
# Get password hash.
|
43
43
|
hash: str | None = mongo_doc.get(field_name)
|
44
44
|
if hash is None:
|
45
45
|
msg = (
|
46
|
-
f"Model: `{cls_model.META['full_model_name']}` > "
|
46
|
+
f"Model: `{cls_model.META['full_model_name']}` > "
|
47
47
|
+ "Method: `verify_password` => "
|
48
48
|
+ f"The model does not have a field `{field_name}`."
|
49
49
|
)
|
@@ -73,9 +73,9 @@ class PasswordMixin:
|
|
73
73
|
if not await self.verify_password(old_password, field_name):
|
74
74
|
raise OldPassNotMatchError()
|
75
75
|
# Get documet ID.
|
76
|
-
doc_id = self._id.value
|
76
|
+
doc_id = self._id.value
|
77
77
|
# Get collection for current Model.
|
78
|
-
collection: AsyncCollection =
|
78
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls_model.META["collection_name"]]
|
79
79
|
# Create hash of new passwor.
|
80
80
|
ph = PasswordHasher()
|
81
81
|
hash: str = ph.hash(new_password)
|
ramifice/paladins/refrash.py
CHANGED
@@ -4,7 +4,7 @@ from typing import Any
|
|
4
4
|
|
5
5
|
from pymongo.asynchronous.collection import AsyncCollection
|
6
6
|
|
7
|
-
from ..utils import
|
7
|
+
from ..utils import globals
|
8
8
|
from ..utils.errors import PanicError
|
9
9
|
from .tools import refresh_from_mongo_doc
|
10
10
|
|
@@ -16,14 +16,14 @@ class RefrashMixin:
|
|
16
16
|
"""Update Model instance from database."""
|
17
17
|
cls_model = self.__class__
|
18
18
|
# Get collection.
|
19
|
-
collection: AsyncCollection =
|
20
|
-
mongo_doc: dict[str, Any] | None = await collection.find_one(filter={"_id": self._id.value})
|
19
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls_model.META["collection_name"]]
|
20
|
+
mongo_doc: dict[str, Any] | None = await collection.find_one(filter={"_id": self._id.value})
|
21
21
|
if mongo_doc is None:
|
22
22
|
msg = (
|
23
|
-
f"Model: `{self.full_model_name()}` > "
|
23
|
+
f"Model: `{self.full_model_name()}` > "
|
24
24
|
+ "Method: `refrash_from_db` => "
|
25
|
-
+ f"A document with an identifier `{self._id.value}` is not exists in the database!"
|
25
|
+
+ f"A document with an identifier `{self._id.value}` is not exists in the database!"
|
26
26
|
)
|
27
27
|
raise PanicError(msg)
|
28
|
-
self.inject()
|
28
|
+
self.inject()
|
29
29
|
refresh_from_mongo_doc(self, mongo_doc)
|
ramifice/paladins/save.py
CHANGED
@@ -5,7 +5,7 @@ from typing import Any
|
|
5
5
|
|
6
6
|
from pymongo.asynchronous.collection import AsyncCollection
|
7
7
|
|
8
|
-
from ..utils import
|
8
|
+
from ..utils import globals
|
9
9
|
from ..utils.errors import PanicError
|
10
10
|
from .tools import ignored_fields_to_none, refresh_from_mongo_doc
|
11
11
|
|
@@ -20,17 +20,17 @@ class SaveMixin:
|
|
20
20
|
"""
|
21
21
|
cls_model = self.__class__
|
22
22
|
# Get collection.
|
23
|
-
collection: AsyncCollection =
|
23
|
+
collection: AsyncCollection = globals.MONGO_DATABASE[cls_model.META["collection_name"]]
|
24
24
|
# Check Model.
|
25
|
-
result_check: dict[str, Any] = await self.check(is_save=True, collection=collection)
|
25
|
+
result_check: dict[str, Any] = await self.check(is_save=True, collection=collection)
|
26
26
|
# Reset the alerts to exclude duplicates.
|
27
|
-
self._id.alerts = []
|
27
|
+
self._id.alerts = []
|
28
28
|
# Check the conditions and, if necessary, define a message for the web form.
|
29
|
-
if not result_check["is_update"] and not cls_model.META["is_create_doc"]:
|
30
|
-
self._id.alerts.append("It is forbidden to create new documents !")
|
29
|
+
if not result_check["is_update"] and not cls_model.META["is_create_doc"]:
|
30
|
+
self._id.alerts.append("It is forbidden to create new documents !")
|
31
31
|
result_check["is_valid"] = False
|
32
|
-
if result_check["is_update"] and not cls_model.META["is_update_doc"]:
|
33
|
-
self._id.alerts.append("It is forbidden to update documents !")
|
32
|
+
if result_check["is_update"] and not cls_model.META["is_update_doc"]:
|
33
|
+
self._id.alerts.append("It is forbidden to update documents !")
|
34
34
|
result_check["is_valid"] = False
|
35
35
|
# Leave the method if the check fails.
|
36
36
|
if not result_check["is_valid"]:
|
@@ -43,18 +43,18 @@ class SaveMixin:
|
|
43
43
|
# Update date and time.
|
44
44
|
checked_data["updated_at"] = datetime.now()
|
45
45
|
# Run hook.
|
46
|
-
await self.pre_update()
|
46
|
+
await self.pre_update()
|
47
47
|
# Update doc.
|
48
48
|
await collection.update_one({"_id": checked_data["_id"]}, {"$set": checked_data})
|
49
49
|
# Run hook.
|
50
|
-
await self.post_update()
|
50
|
+
await self.post_update()
|
51
51
|
# Refresh Model.
|
52
52
|
mongo_doc: dict[str, Any] | None = await collection.find_one(
|
53
53
|
{"_id": checked_data["_id"]}
|
54
54
|
)
|
55
55
|
if mongo_doc is None:
|
56
56
|
msg = (
|
57
|
-
f"Model: `{self.full_model_name()}` > "
|
57
|
+
f"Model: `{self.full_model_name()}` > "
|
58
58
|
+ "Method: `save` => "
|
59
59
|
+ "Geted value is None - it is impossible to refresh the current Model."
|
60
60
|
)
|
@@ -66,16 +66,16 @@ class SaveMixin:
|
|
66
66
|
checked_data["created_at"] = today
|
67
67
|
checked_data["updated_at"] = today
|
68
68
|
# Run hook.
|
69
|
-
await self.pre_create()
|
69
|
+
await self.pre_create()
|
70
70
|
# Insert doc.
|
71
71
|
await collection.insert_one(checked_data)
|
72
72
|
# Run hook.
|
73
|
-
await self.post_create()
|
73
|
+
await self.post_create()
|
74
74
|
# Refresh Model.
|
75
75
|
mongo_doc = await collection.find_one({"_id": checked_data["_id"]})
|
76
76
|
if mongo_doc is None:
|
77
77
|
msg = (
|
78
|
-
f"Model: `{self.full_model_name()}` > "
|
78
|
+
f"Model: `{self.full_model_name()}` > "
|
79
79
|
+ "Method: `save` => "
|
80
80
|
+ "Geted value is None - it is impossible to refresh the current Model."
|
81
81
|
)
|
@@ -84,7 +84,7 @@ class SaveMixin:
|
|
84
84
|
refresh_from_mongo_doc(self, mongo_doc)
|
85
85
|
else:
|
86
86
|
msg = (
|
87
|
-
f"Model: `{self.full_model_name()}` > "
|
87
|
+
f"Model: `{self.full_model_name()}` > "
|
88
88
|
+ "Method: `save` => "
|
89
89
|
+ "The document was not created."
|
90
90
|
)
|
ramifice/paladins/validation.py
CHANGED
@@ -14,7 +14,7 @@ class ValidationMixin:
|
|
14
14
|
The main use is to check data from web forms.
|
15
15
|
It is also used to verify Models that do not migrate to the database.
|
16
16
|
"""
|
17
|
-
result_check: dict[str, Any] = await self.check()
|
17
|
+
result_check: dict[str, Any] = await self.check()
|
18
18
|
return result_check["is_valid"]
|
19
19
|
|
20
20
|
def print_err(self) -> None:
|
@@ -31,17 +31,17 @@ class ValidationMixin:
|
|
31
31
|
if not is_err:
|
32
32
|
print(colored("\nERRORS:", "red", attrs=["bold"]))
|
33
33
|
print(colored("Model: ", "blue", attrs=["bold"]), end="")
|
34
|
-
print(colored(f"`{self.full_model_name()}`", "blue"))
|
34
|
+
print(colored(f"`{self.full_model_name()}`", "blue"))
|
35
35
|
is_err = True
|
36
36
|
# field name
|
37
37
|
print(colored("Field: ", "green", attrs=["bold"]), end="")
|
38
38
|
print(colored(f"`{field_name}`:", "green"))
|
39
39
|
# error messages
|
40
40
|
print(colored("\n".join(field_data.errors), "red"))
|
41
|
-
if len(self._id.alerts) > 0:
|
41
|
+
if len(self._id.alerts) > 0:
|
42
42
|
# title
|
43
43
|
print(colored("AlERTS:", "yellow", attrs=["bold"]))
|
44
44
|
# messages
|
45
|
-
print(colored("\n".join(self._id.alerts), "yellow"), end="\n\n")
|
45
|
+
print(colored("\n".join(self._id.alerts), "yellow"), end="\n\n")
|
46
46
|
else:
|
47
47
|
print(end="\n\n")
|
@@ -1,8 +1,6 @@
|
|
1
|
-
"""Global
|
1
|
+
"""Global variables.
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
The module contains the following elements:
|
3
|
+
List of variables:
|
6
4
|
|
7
5
|
- `DEBUG` - Caching a condition for the verification code.
|
8
6
|
- `MONGO_CLIENT` - Caching a Mongo client.
|