ramifice 0.6.1__py3-none-any.whl → 0.8.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 +2 -1
- ramifice/commons/general.py +9 -9
- ramifice/commons/indexes.py +7 -7
- ramifice/commons/many.py +7 -7
- ramifice/commons/one.py +7 -7
- ramifice/commons/tools.py +0 -1
- ramifice/commons/unit_manager.py +3 -3
- ramifice/fields/bool_field.py +2 -2
- 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 +3 -3
- ramifice/fields/date_field.py +5 -5
- ramifice/fields/date_time_field.py +5 -5
- 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 +5 -5
- 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 +6 -5
- 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 +1 -1
- ramifice/models/model.py +6 -6
- ramifice/paladins/check.py +2 -2
- ramifice/paladins/delete.py +2 -2
- ramifice/paladins/password.py +3 -3
- ramifice/paladins/refrash.py +2 -2
- ramifice/paladins/save.py +2 -2
- ramifice/utils/migration.py +22 -16
- ramifice/utils/mixins/json_converter.py +4 -3
- ramifice/utils/tools.py +1 -1
- {ramifice-0.6.1.dist-info → ramifice-0.8.0.dist-info}/METADATA +4 -3
- ramifice-0.8.0.dist-info/RECORD +84 -0
- ramifice-0.6.1.dist-info/RECORD +0 -84
- /ramifice/utils/{globals.py → constants.py} +0 -0
- {ramifice-0.6.1.dist-info → ramifice-0.8.0.dist-info}/WHEEL +0 -0
- {ramifice-0.6.1.dist-info → ramifice-0.8.0.dist-info}/licenses/LICENSE +0 -0
ramifice/fields/color_field.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from ramifice.fields.general.field import Field
|
4
4
|
from ramifice.fields.general.text_group import TextGroup
|
5
|
-
from ramifice.utils import
|
5
|
+
from ramifice.utils import constants
|
6
6
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
7
7
|
|
8
8
|
|
@@ -31,7 +31,7 @@ class ColorField(Field, TextGroup, JsonMixin):
|
|
31
31
|
readonly: bool = False,
|
32
32
|
unique: bool = False,
|
33
33
|
):
|
34
|
-
if
|
34
|
+
if constants.DEBUG:
|
35
35
|
if default is not None:
|
36
36
|
if not isinstance(default, str):
|
37
37
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -39,7 +39,7 @@ class ColorField(Field, TextGroup, JsonMixin):
|
|
39
39
|
raise AssertionError(
|
40
40
|
"The `default` parameter should not contain an empty string!"
|
41
41
|
)
|
42
|
-
if
|
42
|
+
if constants.REGEX["color_code"].match(default) is None:
|
43
43
|
raise AssertionError("Parameter `default` - Not а color code!")
|
44
44
|
if not isinstance(label, str):
|
45
45
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/date_field.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
"""Field of Model for enter date."""
|
2
2
|
|
3
|
-
import json
|
4
3
|
from datetime import datetime
|
5
4
|
from typing import Any
|
6
5
|
|
6
|
+
import orjson
|
7
7
|
from babel.dates import format_date
|
8
8
|
from dateutil.parser import parse
|
9
9
|
|
10
10
|
from ramifice.fields.general.date_group import DateGroup
|
11
11
|
from ramifice.fields.general.field import Field
|
12
|
-
from ramifice.utils import
|
12
|
+
from ramifice.utils import constants, translations
|
13
13
|
|
14
14
|
|
15
15
|
class DateField(Field, DateGroup):
|
@@ -30,7 +30,7 @@ class DateField(Field, DateGroup):
|
|
30
30
|
max_date: datetime | None = None,
|
31
31
|
min_date: datetime | None = None,
|
32
32
|
):
|
33
|
-
if
|
33
|
+
if constants.DEBUG:
|
34
34
|
if max_date is not None:
|
35
35
|
if not isinstance(max_date, datetime):
|
36
36
|
raise AssertionError("Parameter `max_date` - Not а `str` type!")
|
@@ -109,7 +109,7 @@ class DateField(Field, DateGroup):
|
|
109
109
|
|
110
110
|
def to_json(self) -> str:
|
111
111
|
"""Convert object instance to a JSON string."""
|
112
|
-
return
|
112
|
+
return orjson.dumps(self.to_dict()).decode("utf-8")
|
113
113
|
|
114
114
|
@classmethod
|
115
115
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
@@ -125,5 +125,5 @@ class DateField(Field, DateGroup):
|
|
125
125
|
@classmethod
|
126
126
|
def from_json(cls, json_str: str) -> Any:
|
127
127
|
"""Convert JSON string to a object instance."""
|
128
|
-
json_dict =
|
128
|
+
json_dict = orjson.loads(json_str)
|
129
129
|
return cls.from_dict(json_dict)
|
@@ -1,15 +1,15 @@
|
|
1
1
|
"""Field of Model for enter date and time."""
|
2
2
|
|
3
|
-
import json
|
4
3
|
from datetime import datetime
|
5
4
|
from typing import Any
|
6
5
|
|
6
|
+
import orjson
|
7
7
|
from babel.dates import format_datetime
|
8
8
|
from dateutil.parser import parse
|
9
9
|
|
10
10
|
from ramifice.fields.general.date_group import DateGroup
|
11
11
|
from ramifice.fields.general.field import Field
|
12
|
-
from ramifice.utils import
|
12
|
+
from ramifice.utils import constants, translations
|
13
13
|
|
14
14
|
|
15
15
|
class DateTimeField(Field, DateGroup):
|
@@ -30,7 +30,7 @@ class DateTimeField(Field, DateGroup):
|
|
30
30
|
max_date: datetime | None = None,
|
31
31
|
min_date: datetime | None = None,
|
32
32
|
):
|
33
|
-
if
|
33
|
+
if constants.DEBUG:
|
34
34
|
if max_date is not None:
|
35
35
|
if not isinstance(max_date, datetime):
|
36
36
|
raise AssertionError("Parameter `max_date` - Not а `str` type!")
|
@@ -109,7 +109,7 @@ class DateTimeField(Field, DateGroup):
|
|
109
109
|
|
110
110
|
def to_json(self) -> str:
|
111
111
|
"""Convert object instance to a JSON string."""
|
112
|
-
return
|
112
|
+
return orjson.dumps(self.to_dict()).decode("utf-8")
|
113
113
|
|
114
114
|
@classmethod
|
115
115
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
@@ -125,5 +125,5 @@ class DateTimeField(Field, DateGroup):
|
|
125
125
|
@classmethod
|
126
126
|
def from_json(cls, json_str: str) -> Any:
|
127
127
|
"""Convert JSON string to a object instance."""
|
128
|
-
json_dict =
|
128
|
+
json_dict = orjson.loads(json_str)
|
129
129
|
return cls.from_dict(json_dict)
|
ramifice/fields/email_field.py
CHANGED
@@ -4,7 +4,7 @@ from email_validator import EmailNotValidError, validate_email
|
|
4
4
|
|
5
5
|
from ramifice.fields.general.field import Field
|
6
6
|
from ramifice.fields.general.text_group import TextGroup
|
7
|
-
from ramifice.utils import
|
7
|
+
from ramifice.utils import constants
|
8
8
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
9
9
|
|
10
10
|
|
@@ -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 constants.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
@@ -11,7 +11,7 @@ from aioshutil import copyfile
|
|
11
11
|
|
12
12
|
from ramifice.fields.general.field import Field
|
13
13
|
from ramifice.fields.general.file_group import FileGroup
|
14
|
-
from ramifice.utils import
|
14
|
+
from ramifice.utils import constants
|
15
15
|
from ramifice.utils.errors import FileHasNoExtensionError
|
16
16
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
17
17
|
|
@@ -35,7 +35,7 @@ class FileField(Field, FileGroup, JsonMixin):
|
|
35
35
|
target_dir: str = "files",
|
36
36
|
accept: str = "",
|
37
37
|
):
|
38
|
-
if
|
38
|
+
if constants.DEBUG:
|
39
39
|
if default is not None:
|
40
40
|
if not isinstance(default, str):
|
41
41
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/float_field.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from ramifice.fields.general.field import Field
|
4
4
|
from ramifice.fields.general.number_group import NumberGroup
|
5
|
-
from ramifice.utils import
|
5
|
+
from ramifice.utils import constants
|
6
6
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
7
7
|
|
8
8
|
|
@@ -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 constants.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
@@ -1,12 +1,12 @@
|
|
1
1
|
"""Field of Model for enter identifier of document."""
|
2
2
|
|
3
|
-
import json
|
4
3
|
from typing import Any
|
5
4
|
|
5
|
+
import orjson
|
6
6
|
from bson.objectid import ObjectId
|
7
7
|
|
8
8
|
from ramifice.fields.general.field import Field
|
9
|
-
from ramifice.utils import
|
9
|
+
from ramifice.utils import constants
|
10
10
|
|
11
11
|
|
12
12
|
class IDField(Field):
|
@@ -33,7 +33,7 @@ class IDField(Field):
|
|
33
33
|
readonly: bool = False,
|
34
34
|
unique: bool = False,
|
35
35
|
):
|
36
|
-
if
|
36
|
+
if constants.DEBUG:
|
37
37
|
if not isinstance(label, str):
|
38
38
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
39
39
|
if not isinstance(disabled, bool):
|
@@ -90,7 +90,7 @@ class IDField(Field):
|
|
90
90
|
|
91
91
|
def to_json(self) -> str:
|
92
92
|
"""Convert object instance to a JSON string."""
|
93
|
-
return
|
93
|
+
return orjson.dumps(self.to_dict()).decode("utf-8")
|
94
94
|
|
95
95
|
@classmethod
|
96
96
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
@@ -106,5 +106,5 @@ class IDField(Field):
|
|
106
106
|
@classmethod
|
107
107
|
def from_json(cls, json_str: str) -> Any:
|
108
108
|
"""Convert JSON string to a object instance."""
|
109
|
-
json_dict =
|
109
|
+
json_dict = orjson.loads(json_str)
|
110
110
|
return cls.from_dict(json_dict)
|
ramifice/fields/image_field.py
CHANGED
@@ -11,7 +11,7 @@ from aioshutil import copyfile
|
|
11
11
|
|
12
12
|
from ramifice.fields.general.field import Field
|
13
13
|
from ramifice.fields.general.file_group import FileGroup
|
14
|
-
from ramifice.utils import
|
14
|
+
from ramifice.utils import constants
|
15
15
|
from ramifice.utils.errors import FileHasNoExtensionError
|
16
16
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
17
17
|
|
@@ -38,7 +38,7 @@ class ImageField(Field, FileGroup, JsonMixin):
|
|
38
38
|
# Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
|
39
39
|
thumbnails: dict[str, int] | None = None,
|
40
40
|
):
|
41
|
-
if
|
41
|
+
if constants.DEBUG:
|
42
42
|
if default is not None:
|
43
43
|
if not isinstance(default, str):
|
44
44
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
ramifice/fields/integer_field.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from ramifice.fields.general.field import Field
|
4
4
|
from ramifice.fields.general.number_group import NumberGroup
|
5
|
-
from ramifice.utils import
|
5
|
+
from ramifice.utils import constants
|
6
6
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
7
7
|
|
8
8
|
|
@@ -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 constants.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
@@ -4,7 +4,7 @@ import ipaddress
|
|
4
4
|
|
5
5
|
from ramifice.fields.general.field import Field
|
6
6
|
from ramifice.fields.general.text_group import TextGroup
|
7
|
-
from ramifice.utils import
|
7
|
+
from ramifice.utils import constants
|
8
8
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
9
9
|
|
10
10
|
|
@@ -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 constants.DEBUG:
|
29
29
|
if default is not None:
|
30
30
|
if not isinstance(default, str):
|
31
31
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
@@ -1,10 +1,11 @@
|
|
1
1
|
"""Field of Model for enter password."""
|
2
2
|
|
3
|
-
import json
|
4
3
|
from typing import Any
|
5
4
|
|
5
|
+
import orjson
|
6
|
+
|
6
7
|
from ramifice.fields.general.field import Field
|
7
|
-
from ramifice.utils import
|
8
|
+
from ramifice.utils import constants
|
8
9
|
|
9
10
|
|
10
11
|
class PasswordField(Field):
|
@@ -26,7 +27,7 @@ class PasswordField(Field):
|
|
26
27
|
placeholder: str = "",
|
27
28
|
required: bool = False,
|
28
29
|
):
|
29
|
-
if
|
30
|
+
if constants.DEBUG:
|
30
31
|
if not isinstance(label, str):
|
31
32
|
raise AssertionError("Parameter `default` - Not а `str` type!")
|
32
33
|
if not isinstance(hide, bool):
|
@@ -71,7 +72,7 @@ class PasswordField(Field):
|
|
71
72
|
|
72
73
|
def to_json(self) -> str:
|
73
74
|
"""Convert object instance to a JSON string."""
|
74
|
-
return
|
75
|
+
return orjson.dumps(self.to_dict()).decode("utf-8")
|
75
76
|
|
76
77
|
@classmethod
|
77
78
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
@@ -84,5 +85,5 @@ class PasswordField(Field):
|
|
84
85
|
@classmethod
|
85
86
|
def from_json(cls, json_str: str) -> Any:
|
86
87
|
"""Convert JSON string to a object instance."""
|
87
|
-
json_dict =
|
88
|
+
json_dict = orjson.loads(json_str)
|
88
89
|
return cls.from_dict(json_dict)
|
ramifice/fields/phone_field.py
CHANGED
@@ -4,7 +4,7 @@ import phonenumbers
|
|
4
4
|
|
5
5
|
from ramifice.fields.general.field import Field
|
6
6
|
from ramifice.fields.general.text_group import TextGroup
|
7
|
-
from ramifice.utils import
|
7
|
+
from ramifice.utils import constants
|
8
8
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
9
9
|
|
10
10
|
|
@@ -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 constants.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
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from ramifice.fields.general.field import Field
|
4
4
|
from ramifice.fields.general.text_group import TextGroup
|
5
|
-
from ramifice.utils import
|
5
|
+
from ramifice.utils import constants
|
6
6
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
7
7
|
|
8
8
|
|
@@ -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 constants.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,7 +1,7 @@
|
|
1
1
|
"""Field of Model for enter text."""
|
2
2
|
|
3
3
|
from ramifice.fields.general.field import Field
|
4
|
-
from ramifice.utils import
|
4
|
+
from ramifice.utils import constants
|
5
5
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
6
6
|
|
7
7
|
|
@@ -26,7 +26,7 @@ class TextField(Field, JsonMixin):
|
|
26
26
|
# Support for several language.
|
27
27
|
multi_language: bool = False,
|
28
28
|
):
|
29
|
-
if
|
29
|
+
if constants.DEBUG:
|
30
30
|
if not isinstance(maxlength, int):
|
31
31
|
raise AssertionError("Parameter `maxlength` - Not а `int` type!")
|
32
32
|
if not isinstance(label, str):
|
ramifice/fields/url_field.py
CHANGED
@@ -4,7 +4,7 @@ from urllib.parse import urlparse
|
|
4
4
|
|
5
5
|
from ramifice.fields.general.field import Field
|
6
6
|
from ramifice.fields.general.text_group import TextGroup
|
7
|
-
from ramifice.utils import
|
7
|
+
from ramifice.utils import constants
|
8
8
|
from ramifice.utils.mixins.json_converter import JsonMixin
|
9
9
|
|
10
10
|
|
@@ -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 constants.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
@@ -8,8 +8,8 @@ from ramifice.commons import QCommonsMixin
|
|
8
8
|
from ramifice.fields import DateTimeField, IDField
|
9
9
|
from ramifice.models.model import Model
|
10
10
|
from ramifice.paladins import QPaladinsMixin
|
11
|
+
from ramifice.utils.constants import REGEX
|
11
12
|
from ramifice.utils.errors import DoesNotMatchRegexError, PanicError
|
12
|
-
from ramifice.utils.globals import REGEX
|
13
13
|
from ramifice.utils.mixins.add_valid import AddValidMixin
|
14
14
|
from ramifice.utils.mixins.hooks import HooksMixin
|
15
15
|
from ramifice.utils.mixins.indexing import IndexMixin
|
ramifice/models/model.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
"""For converting Python classes into Ramifice models."""
|
2
2
|
|
3
|
-
import json
|
4
3
|
from abc import ABCMeta, abstractmethod
|
5
4
|
from typing import Any
|
6
5
|
|
6
|
+
import orjson
|
7
7
|
from babel.dates import format_date, format_datetime
|
8
8
|
from bson.objectid import ObjectId
|
9
9
|
from dateutil.parser import parse
|
@@ -79,7 +79,7 @@ class Model(metaclass=ABCMeta):
|
|
79
79
|
dyn_data = data_dynamic_fields[f_name]
|
80
80
|
if dyn_data is not None:
|
81
81
|
f_type.choices = [
|
82
|
-
|
82
|
+
[item["value"], item["title"][lang]] for item in dyn_data
|
83
83
|
]
|
84
84
|
else:
|
85
85
|
# This is necessary for
|
@@ -98,7 +98,7 @@ class Model(metaclass=ABCMeta):
|
|
98
98
|
|
99
99
|
def to_json(self) -> str:
|
100
100
|
"""Convert object instance to a JSON string."""
|
101
|
-
return
|
101
|
+
return orjson.dumps(self.to_dict()).decode("utf-8")
|
102
102
|
|
103
103
|
@classmethod
|
104
104
|
def from_dict(cls, json_dict: dict[str, Any]) -> Any:
|
@@ -111,7 +111,7 @@ class Model(metaclass=ABCMeta):
|
|
111
111
|
@classmethod
|
112
112
|
def from_json(cls, json_str: str) -> Any:
|
113
113
|
"""Convert JSON string to a object instance."""
|
114
|
-
json_dict =
|
114
|
+
json_dict = orjson.loads(json_str)
|
115
115
|
return cls.from_dict(json_dict)
|
116
116
|
|
117
117
|
# --------------------------------------------------------------------------
|
@@ -148,7 +148,7 @@ class Model(metaclass=ABCMeta):
|
|
148
148
|
|
149
149
|
def to_json_only_value(self) -> str:
|
150
150
|
"""Convert model.field.value (only the `value` attribute) to a JSON string."""
|
151
|
-
return
|
151
|
+
return orjson.dumps(self.to_dict_only_value()).decode("utf-8")
|
152
152
|
|
153
153
|
@classmethod
|
154
154
|
def from_dict_only_value(cls, json_dict: dict[str, Any]) -> Any:
|
@@ -170,7 +170,7 @@ class Model(metaclass=ABCMeta):
|
|
170
170
|
@classmethod
|
171
171
|
def from_json_only_value(cls, json_str: str) -> Any:
|
172
172
|
"""Convert JSON string to a object instance."""
|
173
|
-
json_dict =
|
173
|
+
json_dict = orjson.loads(json_str)
|
174
174
|
return cls.from_dict_only_value(json_dict)
|
175
175
|
|
176
176
|
def refrash_fields_only_value(self, only_value_dict: dict[str, Any]) -> None:
|
ramifice/paladins/check.py
CHANGED
@@ -19,7 +19,7 @@ from ramifice.paladins.groups import (
|
|
19
19
|
SlugGroupMixin,
|
20
20
|
TextGroupMixin,
|
21
21
|
)
|
22
|
-
from ramifice.utils import
|
22
|
+
from ramifice.utils import constants
|
23
23
|
from ramifice.utils.errors import PanicError
|
24
24
|
|
25
25
|
|
@@ -63,7 +63,7 @@ class CheckMixin(
|
|
63
63
|
error_map: dict[str, str] = await self.add_validation() or {}
|
64
64
|
# Get Model collection.
|
65
65
|
if collection is None:
|
66
|
-
collection =
|
66
|
+
collection = constants.MONGO_DATABASE[cls_model.META["collection_name"]]
|
67
67
|
# Create params for *_group methods.
|
68
68
|
params: dict[str, Any] = {
|
69
69
|
"doc_id": doc_id,
|
ramifice/paladins/delete.py
CHANGED
@@ -6,7 +6,7 @@ from aiofiles import os
|
|
6
6
|
from aioshutil import rmtree
|
7
7
|
from pymongo.asynchronous.collection import AsyncCollection
|
8
8
|
|
9
|
-
from ramifice.utils import
|
9
|
+
from ramifice.utils import constants
|
10
10
|
from ramifice.utils.errors import PanicError
|
11
11
|
|
12
12
|
|
@@ -46,7 +46,7 @@ class DeleteMixin:
|
|
46
46
|
# Run hook.
|
47
47
|
await self.pre_delete()
|
48
48
|
# Get collection for current Model.
|
49
|
-
collection: AsyncCollection =
|
49
|
+
collection: AsyncCollection = constants.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(
|
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 ramifice.utils import
|
8
|
+
from ramifice.utils import constants
|
9
9
|
from ramifice.utils.errors import OldPassNotMatchError, PanicError
|
10
10
|
|
11
11
|
|
@@ -29,7 +29,7 @@ class PasswordMixin:
|
|
29
29
|
)
|
30
30
|
raise PanicError(msg)
|
31
31
|
# Get collection for current Model.
|
32
|
-
collection: AsyncCollection =
|
32
|
+
collection: AsyncCollection = constants.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:
|
@@ -75,7 +75,7 @@ class PasswordMixin:
|
|
75
75
|
# Get documet ID.
|
76
76
|
doc_id = self._id.value
|
77
77
|
# Get collection for current Model.
|
78
|
-
collection: AsyncCollection =
|
78
|
+
collection: AsyncCollection = constants.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
@@ -5,7 +5,7 @@ from typing import Any
|
|
5
5
|
from pymongo.asynchronous.collection import AsyncCollection
|
6
6
|
|
7
7
|
from ramifice.paladins.tools import refresh_from_mongo_doc
|
8
|
-
from ramifice.utils import
|
8
|
+
from ramifice.utils import constants
|
9
9
|
from ramifice.utils.errors import PanicError
|
10
10
|
|
11
11
|
|
@@ -16,7 +16,7 @@ class RefrashMixin:
|
|
16
16
|
"""Update Model instance from database."""
|
17
17
|
cls_model = self.__class__
|
18
18
|
# Get collection.
|
19
|
-
collection: AsyncCollection =
|
19
|
+
collection: AsyncCollection = constants.MONGO_DATABASE[cls_model.META["collection_name"]]
|
20
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 = (
|
ramifice/paladins/save.py
CHANGED
@@ -6,7 +6,7 @@ from typing import Any
|
|
6
6
|
from pymongo.asynchronous.collection import AsyncCollection
|
7
7
|
|
8
8
|
from ramifice.paladins.tools import ignored_fields_to_none, refresh_from_mongo_doc
|
9
|
-
from ramifice.utils import
|
9
|
+
from ramifice.utils import constants
|
10
10
|
from ramifice.utils.errors import PanicError
|
11
11
|
|
12
12
|
|
@@ -20,7 +20,7 @@ class SaveMixin:
|
|
20
20
|
"""
|
21
21
|
cls_model = self.__class__
|
22
22
|
# Get collection.
|
23
|
-
collection: AsyncCollection =
|
23
|
+
collection: AsyncCollection = constants.MONGO_DATABASE[cls_model.META["collection_name"]]
|
24
24
|
# Check Model.
|
25
25
|
result_check: dict[str, Any] = await self.check(is_save=True, collection=collection)
|
26
26
|
# Reset the alerts to exclude duplicates.
|
ramifice/utils/migration.py
CHANGED
@@ -12,24 +12,24 @@ from pymongo.asynchronous.collection import AsyncCollection
|
|
12
12
|
from termcolor import colored
|
13
13
|
|
14
14
|
from ramifice.models.model import Model
|
15
|
-
from ramifice.utils import
|
15
|
+
from ramifice.utils import constants
|
16
16
|
from ramifice.utils.errors import DoesNotMatchRegexError, NoModelsForMigrationError, PanicError
|
17
17
|
from ramifice.utils.fixtures import apply_fixture
|
18
18
|
|
19
19
|
|
20
|
-
class
|
21
|
-
"""
|
20
|
+
class Migration:
|
21
|
+
"""Migration of models to database."""
|
22
22
|
|
23
23
|
def __init__(self, database_name: str, mongo_client: AsyncMongoClient): # noqa: D107
|
24
|
-
|
24
|
+
constants.DEBUG = False
|
25
25
|
#
|
26
|
-
db_name_regex =
|
26
|
+
db_name_regex = constants.REGEX["database_name"]
|
27
27
|
if db_name_regex.match(database_name) is None:
|
28
28
|
raise DoesNotMatchRegexError("^[a-zA-Z][-_a-zA-Z0-9]{0,59}$")
|
29
29
|
#
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
constants.DATABASE_NAME = database_name
|
31
|
+
constants.MONGO_CLIENT = mongo_client
|
32
|
+
constants.MONGO_DATABASE = constants.MONGO_CLIENT[constants.DATABASE_NAME]
|
33
33
|
# Get Model list.
|
34
34
|
self.model_list: list[Any] = Model.__subclasses__()
|
35
35
|
# Raise the exception if there are no models for migration.
|
@@ -43,7 +43,9 @@ class Monitor:
|
|
43
43
|
"""
|
44
44
|
# Get access to super collection.
|
45
45
|
# (Contains Model state and dynamic field data.)
|
46
|
-
super_collection: AsyncCollection =
|
46
|
+
super_collection: AsyncCollection = constants.MONGO_DATABASE[
|
47
|
+
constants.SUPER_COLLECTION_NAME
|
48
|
+
]
|
47
49
|
# Switch the `is_model_exist` parameter in `False`.
|
48
50
|
async for model_state in super_collection.find():
|
49
51
|
q_filter = {"collection_name": model_state["collection_name"]}
|
@@ -54,7 +56,9 @@ class Monitor:
|
|
54
56
|
"""Get the state of the current model from a super collection."""
|
55
57
|
# Get access to super collection.
|
56
58
|
# (Contains Model state and dynamic field data.)
|
57
|
-
super_collection: AsyncCollection =
|
59
|
+
super_collection: AsyncCollection = constants.MONGO_DATABASE[
|
60
|
+
constants.SUPER_COLLECTION_NAME
|
61
|
+
]
|
58
62
|
# Get state of current Model.
|
59
63
|
model_state: dict[str, Any] | None = await super_collection.find_one(
|
60
64
|
{"collection_name": metadata["collection_name"]}
|
@@ -86,10 +90,12 @@ class Monitor:
|
|
86
90
|
delete collections associated with those Models.
|
87
91
|
""" # noqa: D205
|
88
92
|
# Get access to database.
|
89
|
-
database =
|
93
|
+
database = constants.MONGO_DATABASE
|
90
94
|
# Get access to super collection.
|
91
95
|
# (Contains Model state and dynamic field data.)
|
92
|
-
super_collection: AsyncCollection =
|
96
|
+
super_collection: AsyncCollection = constants.MONGO_DATABASE[
|
97
|
+
constants.SUPER_COLLECTION_NAME
|
98
|
+
]
|
93
99
|
# Delete data for non-existent Models.
|
94
100
|
async for model_state in super_collection.find():
|
95
101
|
if model_state["is_model_exist"] is False:
|
@@ -111,9 +117,9 @@ class Monitor:
|
|
111
117
|
# Switch the `is_model_exist` parameter in the condition `False`.
|
112
118
|
await self.reset()
|
113
119
|
# Get access to database.
|
114
|
-
database =
|
120
|
+
database = constants.MONGO_DATABASE
|
115
121
|
# Get access to super collection.
|
116
|
-
super_collection: AsyncCollection = database[
|
122
|
+
super_collection: AsyncCollection = database[constants.SUPER_COLLECTION_NAME]
|
117
123
|
#
|
118
124
|
for cls_model in self.model_list:
|
119
125
|
# Get metadata of current Model.
|
@@ -195,7 +201,7 @@ class Monitor:
|
|
195
201
|
)
|
196
202
|
#
|
197
203
|
# Block the verification code.
|
198
|
-
|
204
|
+
constants.DEBUG = False
|
199
205
|
#
|
200
206
|
# Delete data for non-existent Models from a
|
201
207
|
# super collection and delete collections associated with those Models.
|
@@ -207,7 +213,7 @@ class Monitor:
|
|
207
213
|
# Apply fixture to current Model.
|
208
214
|
fixture_name: str | None = cls_model.META["fixture_name"]
|
209
215
|
if fixture_name is not None:
|
210
|
-
collection: AsyncCollection =
|
216
|
+
collection: AsyncCollection = constants.MONGO_DATABASE[
|
211
217
|
cls_model.META["collection_name"]
|
212
218
|
]
|
213
219
|
if await collection.estimated_document_count() == 0:
|