ramifice 0.8.11__py3-none-any.whl → 0.8.13__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.
Files changed (84) hide show
  1. ramifice/__init__.py +16 -1
  2. ramifice/commons/__init__.py +2 -2
  3. ramifice/commons/general.py +11 -11
  4. ramifice/commons/indexes.py +8 -8
  5. ramifice/commons/many.py +10 -6
  6. ramifice/commons/one.py +13 -8
  7. ramifice/commons/tools.py +4 -4
  8. ramifice/commons/unit_manager.py +15 -5
  9. ramifice/fields/__init__.py +1 -1
  10. ramifice/fields/bool_field.py +26 -18
  11. ramifice/fields/choice_float_dyn_field.py +29 -21
  12. ramifice/fields/choice_float_field.py +41 -33
  13. ramifice/fields/choice_float_mult_dyn_field.py +29 -21
  14. ramifice/fields/choice_float_mult_field.py +48 -40
  15. ramifice/fields/choice_int_dyn_field.py +29 -21
  16. ramifice/fields/choice_int_field.py +41 -33
  17. ramifice/fields/choice_int_mult_dyn_field.py +29 -21
  18. ramifice/fields/choice_int_mult_field.py +48 -40
  19. ramifice/fields/choice_text_dyn_field.py +29 -21
  20. ramifice/fields/choice_text_field.py +47 -39
  21. ramifice/fields/choice_text_mult_dyn_field.py +29 -21
  22. ramifice/fields/choice_text_mult_field.py +48 -40
  23. ramifice/fields/color_field.py +40 -32
  24. ramifice/fields/date_field.py +49 -40
  25. ramifice/fields/date_time_field.py +49 -40
  26. ramifice/fields/email_field.py +42 -34
  27. ramifice/fields/file_field.py +45 -35
  28. ramifice/fields/float_field.py +56 -47
  29. ramifice/fields/general/__init__.py +1 -1
  30. ramifice/fields/general/choice_group.py +2 -2
  31. ramifice/fields/general/date_group.py +2 -2
  32. ramifice/fields/general/field.py +2 -2
  33. ramifice/fields/general/file_group.py +2 -2
  34. ramifice/fields/general/number_group.py +2 -2
  35. ramifice/fields/general/text_group.py +3 -3
  36. ramifice/fields/id_field.py +35 -28
  37. ramifice/fields/image_field.py +67 -57
  38. ramifice/fields/integer_field.py +56 -47
  39. ramifice/fields/ip_field.py +41 -34
  40. ramifice/fields/password_field.py +29 -22
  41. ramifice/fields/phone_field.py +44 -36
  42. ramifice/fields/slug_field.py +30 -22
  43. ramifice/fields/text_field.py +43 -35
  44. ramifice/fields/url_field.py +40 -33
  45. ramifice/models/__init__.py +1 -1
  46. ramifice/models/decorator.py +33 -11
  47. ramifice/models/model.py +16 -16
  48. ramifice/paladins/__init__.py +2 -2
  49. ramifice/paladins/check.py +8 -3
  50. ramifice/paladins/delete.py +9 -3
  51. ramifice/paladins/groups/__init__.py +1 -1
  52. ramifice/paladins/groups/bool_group.py +3 -3
  53. ramifice/paladins/groups/choice_group.py +3 -3
  54. ramifice/paladins/groups/date_group.py +3 -3
  55. ramifice/paladins/groups/file_group.py +3 -3
  56. ramifice/paladins/groups/id_group.py +3 -3
  57. ramifice/paladins/groups/img_group.py +3 -3
  58. ramifice/paladins/groups/num_group.py +3 -3
  59. ramifice/paladins/groups/pass_group.py +3 -3
  60. ramifice/paladins/groups/slug_group.py +8 -3
  61. ramifice/paladins/groups/text_group.py +3 -3
  62. ramifice/paladins/password.py +11 -4
  63. ramifice/paladins/refrash.py +7 -3
  64. ramifice/paladins/save.py +9 -3
  65. ramifice/paladins/tools.py +11 -6
  66. ramifice/paladins/validation.py +4 -4
  67. ramifice/utils/__init__.py +1 -1
  68. ramifice/utils/constants.py +1 -1
  69. ramifice/utils/errors.py +7 -7
  70. ramifice/utils/fixtures.py +7 -2
  71. ramifice/utils/migration.py +18 -9
  72. ramifice/utils/mixins/__init__.py +1 -1
  73. ramifice/utils/mixins/add_valid.py +3 -3
  74. ramifice/utils/mixins/hooks.py +8 -8
  75. ramifice/utils/mixins/indexing.py +3 -3
  76. ramifice/utils/mixins/json_converter.py +6 -6
  77. ramifice/utils/tools.py +12 -12
  78. ramifice/utils/translations.py +24 -8
  79. ramifice/utils/unit.py +8 -3
  80. {ramifice-0.8.11.dist-info → ramifice-0.8.13.dist-info}/METADATA +9 -5
  81. ramifice-0.8.13.dist-info/RECORD +84 -0
  82. ramifice-0.8.11.dist-info/RECORD +0 -84
  83. {ramifice-0.8.11.dist-info → ramifice-0.8.13.dist-info}/WHEEL +0 -0
  84. {ramifice-0.8.11.dist-info → ramifice-0.8.13.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
1
- """Group for checking slug fields.
1
+ """Ramifice - Group for checking slug fields.
2
2
 
3
3
  Supported fields:
4
4
  SlugField
@@ -6,6 +6,7 @@ Supported fields:
6
6
 
7
7
  __all__ = ("SlugGroupMixin",)
8
8
 
9
+ import logging
9
10
  from typing import Any
10
11
 
11
12
  from slugify import slugify
@@ -13,16 +14,18 @@ from slugify import slugify
13
14
  from ramifice.paladins.tools import check_uniqueness
14
15
  from ramifice.utils.errors import PanicError
15
16
 
17
+ logger = logging.getLogger(__name__)
18
+
16
19
 
17
20
  class SlugGroupMixin:
18
- """Group for checking slug fields.
21
+ """Ramifice - Group for checking slug fields.
19
22
 
20
23
  Supported fields:
21
24
  SlugField
22
25
  """
23
26
 
24
27
  async def slug_group(self, params: dict[str, Any]) -> None:
25
- """Checking slug fields."""
28
+ """Ramifice - Checking slug fields."""
26
29
  if not params["is_save"]:
27
30
  return
28
31
  #
@@ -48,6 +51,7 @@ class SlugGroupMixin:
48
51
  + "This field is specified in slug_sources. "
49
52
  + "This field should be mandatory or assign a default value."
50
53
  )
54
+ logger.error(err_msg)
51
55
  raise PanicError(err_msg)
52
56
  # Insert result.
53
57
  if params["is_save"]:
@@ -65,6 +69,7 @@ class SlugGroupMixin:
65
69
  + f"Parameter: `slug_sources` => "
66
70
  + "At least one field should be unique!"
67
71
  )
72
+ logger.error(err_msg)
68
73
  raise PanicError(err_msg)
69
74
  # Add value to map.
70
75
  params["result_map"][field_name] = value
@@ -1,4 +1,4 @@
1
- """Group for checking text fields.
1
+ """Ramifice - Group for checking text fields.
2
2
 
3
3
  Supported fields:
4
4
  URLField | TextField | PhoneField
@@ -30,7 +30,7 @@ from ramifice.utils.tools import (
30
30
 
31
31
 
32
32
  class TextGroupMixin:
33
- """Group for checking text fields.
33
+ """Ramifice - Group for checking text fields.
34
34
 
35
35
  Supported fields:
36
36
  URLField | TextField | PhoneField
@@ -38,7 +38,7 @@ class TextGroupMixin:
38
38
  """
39
39
 
40
40
  async def text_group(self, params: dict[str, Any]) -> None:
41
- """Checking text fields."""
41
+ """Ramifice - Checking text fields."""
42
42
  field = params["field_data"]
43
43
  field_name = field.name
44
44
  field_type: str = field.field_type
@@ -1,7 +1,8 @@
1
- """Verification, replacement and recoverang of password."""
1
+ """Ramifice - Verification, replacement and recoverang of password."""
2
2
 
3
3
  __all__ = ("PasswordMixin",)
4
4
 
5
+ import logging
5
6
  from typing import Any
6
7
 
7
8
  from argon2 import PasswordHasher
@@ -10,16 +11,18 @@ from pymongo.asynchronous.collection import AsyncCollection
10
11
  from ramifice.utils import constants
11
12
  from ramifice.utils.errors import OldPassNotMatchError, PanicError
12
13
 
14
+ logger = logging.getLogger(__name__)
15
+
13
16
 
14
17
  class PasswordMixin:
15
- """Verification, replacement and recoverang of password."""
18
+ """Ramifice - Verification, replacement and recoverang of password."""
16
19
 
17
20
  async def verify_password(
18
21
  self,
19
22
  password: str,
20
23
  field_name: str = "password",
21
24
  ) -> bool:
22
- """For password verification."""
25
+ """Ramifice - For password verification."""
23
26
  cls_model = self.__class__
24
27
  # Get documet ID.
25
28
  doc_id = self._id.value
@@ -29,6 +32,7 @@ class PasswordMixin:
29
32
  + "Method: `verify_password` => "
30
33
  + "Cannot get document ID - ID field is empty."
31
34
  )
35
+ logger.error(msg)
32
36
  raise PanicError(msg)
33
37
  # Get collection for current Model.
34
38
  collection: AsyncCollection = constants.MONGO_DATABASE[cls_model.META["collection_name"]]
@@ -40,6 +44,7 @@ class PasswordMixin:
40
44
  + "Method: `verify_password` => "
41
45
  + f"There is no document with ID `{self._id.value}` in the database."
42
46
  )
47
+ logger.error(msg)
43
48
  raise PanicError(msg)
44
49
  # Get password hash.
45
50
  hash: str | None = mongo_doc.get(field_name)
@@ -49,6 +54,7 @@ class PasswordMixin:
49
54
  + "Method: `verify_password` => "
50
55
  + f"The model does not have a field `{field_name}`."
51
56
  )
57
+ logger.error(msg)
52
58
  raise PanicError(msg)
53
59
  # Password verification.
54
60
  is_valid: bool = False
@@ -70,9 +76,10 @@ class PasswordMixin:
70
76
  new_password: str,
71
77
  field_name: str = "password",
72
78
  ) -> None:
73
- """For replace or recover password."""
79
+ """Ramifice - For replace or recover password."""
74
80
  cls_model = self.__class__
75
81
  if not await self.verify_password(old_password, field_name):
82
+ logger.warning("Old password does not match!")
76
83
  raise OldPassNotMatchError()
77
84
  # Get documet ID.
78
85
  doc_id = self._id.value
@@ -1,7 +1,8 @@
1
- """Update Model instance from database."""
1
+ """Ramifice - Update Model instance from database."""
2
2
 
3
3
  __all__ = ("RefrashMixin",)
4
4
 
5
+ import logging
5
6
  from typing import Any
6
7
 
7
8
  from pymongo.asynchronous.collection import AsyncCollection
@@ -10,12 +11,14 @@ from ramifice.paladins.tools import refresh_from_mongo_doc
10
11
  from ramifice.utils import constants
11
12
  from ramifice.utils.errors import PanicError
12
13
 
14
+ logger = logging.getLogger(__name__)
15
+
13
16
 
14
17
  class RefrashMixin:
15
- """Update Model instance from database."""
18
+ """Ramifice - Update Model instance from database."""
16
19
 
17
20
  async def refrash_from_db(self) -> None:
18
- """Update Model instance from database."""
21
+ """Ramifice - Update Model instance from database."""
19
22
  cls_model = self.__class__
20
23
  # Get collection.
21
24
  collection: AsyncCollection = constants.MONGO_DATABASE[cls_model.META["collection_name"]]
@@ -26,6 +29,7 @@ class RefrashMixin:
26
29
  + "Method: `refrash_from_db` => "
27
30
  + f"A document with an identifier `{self._id.value}` is not exists in the database!"
28
31
  )
32
+ logger.error(msg)
29
33
  raise PanicError(msg)
30
34
  self.inject()
31
35
  refresh_from_mongo_doc(self, mongo_doc)
ramifice/paladins/save.py CHANGED
@@ -1,7 +1,8 @@
1
- """Create or update document in database."""
1
+ """Ramifice - Create or update document in database."""
2
2
 
3
3
  __all__ = ("SaveMixin",)
4
4
 
5
+ import logging
5
6
  from datetime import datetime
6
7
  from typing import Any
7
8
 
@@ -11,12 +12,14 @@ from ramifice.paladins.tools import ignored_fields_to_none, refresh_from_mongo_d
11
12
  from ramifice.utils import constants
12
13
  from ramifice.utils.errors import PanicError
13
14
 
15
+ logger = logging.getLogger(__name__)
16
+
14
17
 
15
18
  class SaveMixin:
16
- """Create or update document in database."""
19
+ """Ramifice - Create or update document in database."""
17
20
 
18
21
  async def save(self) -> bool:
19
- """Create or update document in database.
22
+ """Ramifice - Create or update document in database.
20
23
 
21
24
  This method pre-uses the `check` method.
22
25
  """
@@ -60,6 +63,7 @@ class SaveMixin:
60
63
  + "Method: `save` => "
61
64
  + "Geted value is None - it is impossible to refresh the current Model."
62
65
  )
66
+ logger.error(msg)
63
67
  raise PanicError(msg)
64
68
  refresh_from_mongo_doc(self, mongo_doc)
65
69
  else:
@@ -81,6 +85,7 @@ class SaveMixin:
81
85
  + "Method: `save` => "
82
86
  + "Geted value is None - it is impossible to refresh the current Model."
83
87
  )
88
+ logger.error(msg)
84
89
  raise PanicError(msg)
85
90
  if mongo_doc is not None:
86
91
  refresh_from_mongo_doc(self, mongo_doc)
@@ -90,6 +95,7 @@ class SaveMixin:
90
95
  + "Method: `save` => "
91
96
  + "The document was not created."
92
97
  )
98
+ logger.error(msg)
93
99
  raise PanicError(msg)
94
100
  #
95
101
  # If everything is completed successfully.
@@ -1,4 +1,4 @@
1
- """Tool of Paladins - A set of auxiliary methods."""
1
+ """Ramifice - Tool of Paladins - A set of auxiliary methods."""
2
2
 
3
3
  __all__ = (
4
4
  "ignored_fields_to_none",
@@ -8,20 +8,23 @@ __all__ = (
8
8
  "check_uniqueness",
9
9
  )
10
10
 
11
+ import logging
11
12
  from typing import Any
12
13
 
13
14
  from ramifice.utils import errors, translations
14
15
 
16
+ logger = logging.getLogger(__name__)
17
+
15
18
 
16
19
  def ignored_fields_to_none(inst_model: Any) -> None:
17
- """Reset the values of ignored fields to None."""
20
+ """Ramifice - Reset the values of ignored fields to None."""
18
21
  for _, field_data in inst_model.__dict__.items():
19
22
  if not callable(field_data) and field_data.ignored:
20
23
  field_data.value = None
21
24
 
22
25
 
23
26
  def refresh_from_mongo_doc(inst_model: Any, mongo_doc: dict[str, Any]) -> None:
24
- """Update object instance from Mongo document."""
27
+ """Ramifice - Update object instance from Mongo document."""
25
28
  lang: str = translations.CURRENT_LOCALE
26
29
  model_dict = inst_model.__dict__
27
30
  for name, data in mongo_doc.items():
@@ -35,17 +38,18 @@ def refresh_from_mongo_doc(inst_model: Any, mongo_doc: dict[str, Any]) -> None:
35
38
 
36
39
 
37
40
  def panic_type_error(value_type: str, params: dict[str, Any]) -> None:
38
- """Unacceptable type of value."""
41
+ """Ramifice - Unacceptable type of value."""
39
42
  msg = (
40
43
  f"Model: `{params['full_model_name']}` > "
41
44
  + f"Field: `{params['field_data'].name}` > "
42
45
  + f"Parameter: `value` => Must be `{value_type}` type!"
43
46
  )
47
+ logger.error(msg)
44
48
  raise errors.PanicError(msg)
45
49
 
46
50
 
47
51
  def accumulate_error(err_msg: str, params: dict[str, Any]) -> None:
48
- """For accumulating errors to ModelName.field_name.errors ."""
52
+ """Ramifice - Accumulating errors to ModelName.field_name.errors ."""
49
53
  if not params["field_data"].hide:
50
54
  params["field_data"].errors.append(err_msg)
51
55
  if not params["is_error_symptom"]:
@@ -56,6 +60,7 @@ def accumulate_error(err_msg: str, params: dict[str, Any]) -> None:
56
60
  + f"Field: `{params['field_data'].name}`"
57
61
  + f" => {err_msg}"
58
62
  )
63
+ logger.error(msg)
59
64
  raise errors.PanicError(msg)
60
65
 
61
66
 
@@ -65,7 +70,7 @@ async def check_uniqueness(
65
70
  field_name: str | None = None,
66
71
  is_multi_language: bool = False,
67
72
  ) -> bool:
68
- """Check the uniqueness of the value in the collection."""
73
+ """Ramifice - Checking the uniqueness of the value in the collection."""
69
74
  q_filter = None
70
75
  if is_multi_language:
71
76
  lang_filter = [{f"{field_name}.{lang}": value} for lang in translations.LANGUAGES]
@@ -1,4 +1,4 @@
1
- """Validation of Model and printing errors to console."""
1
+ """Ramifice - Validation of Model and printing errors to console."""
2
2
 
3
3
  __all__ = ("ValidationMixin",)
4
4
 
@@ -8,10 +8,10 @@ from termcolor import colored
8
8
 
9
9
 
10
10
  class ValidationMixin:
11
- """Validation of Model and printing errors to console."""
11
+ """Ramifice - Validation of Model and printing errors to console."""
12
12
 
13
13
  async def is_valid(self) -> bool:
14
- """Check data validity.
14
+ """Ramifice - Check data validity.
15
15
 
16
16
  The main use is to check data from web forms.
17
17
  It is also used to verify Models that do not migrate to the database.
@@ -20,7 +20,7 @@ class ValidationMixin:
20
20
  return result_check["is_valid"]
21
21
 
22
22
  def print_err(self) -> None:
23
- """Printing errors to console.
23
+ """Ramifice - Printing errors to console.
24
24
 
25
25
  Convenient to use during development.
26
26
  """
@@ -1 +1 @@
1
- """A set of Ramifice useful utilities."""
1
+ """Ramifice - A set of Ramifice useful utilities."""
@@ -1,4 +1,4 @@
1
- """Global variables.
1
+ """Ramifice - Global variables.
2
2
 
3
3
  List of variables:
4
4
 
ramifice/utils/errors.py CHANGED
@@ -1,15 +1,15 @@
1
- """Custom Exceptions for Ramifice."""
1
+ """Ramifice - Custom Exceptions for Ramifice."""
2
2
 
3
3
 
4
4
  class RamificeException(Exception):
5
- """Root Exception for Ramifice."""
5
+ """Ramifice - Root Exception for Ramifice."""
6
6
 
7
7
  def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] # noqa: D107
8
8
  super().__init__(*args, **kwargs)
9
9
 
10
10
 
11
11
  class FileHasNoExtensionError(RamificeException):
12
- """Exception raised if the file has no extension.
12
+ """Ramifice - Exception raised if the file has no extension.
13
13
 
14
14
  Attributes:
15
15
  message -- explanation of the error
@@ -21,7 +21,7 @@ class FileHasNoExtensionError(RamificeException):
21
21
 
22
22
 
23
23
  class DoesNotMatchRegexError(RamificeException):
24
- """Exception raised if does not match the regular expression.
24
+ """Ramifice - Exception raised if does not match the regular expression.
25
25
 
26
26
  Attributes:
27
27
  regex_str -- regular expression in string representation
@@ -33,7 +33,7 @@ class DoesNotMatchRegexError(RamificeException):
33
33
 
34
34
 
35
35
  class NoModelsForMigrationError(RamificeException):
36
- """Exception raised if no Models for migration."""
36
+ """Ramifice - Exception raised if no Models for migration."""
37
37
 
38
38
  def __init__(self): # type: ignore[no-untyped-def] # noqa: D107
39
39
  self.message = "No Models for Migration!"
@@ -41,7 +41,7 @@ class NoModelsForMigrationError(RamificeException):
41
41
 
42
42
 
43
43
  class PanicError(RamificeException):
44
- """Exception raised for cases of which should not be.
44
+ """Ramifice - Exception raised for cases of which should not be.
45
45
 
46
46
  Attributes:
47
47
  message -- explanation of the error
@@ -53,7 +53,7 @@ class PanicError(RamificeException):
53
53
 
54
54
 
55
55
  class OldPassNotMatchError(RamificeException):
56
- """Exception raised if when updating the password,
56
+ """Ramifice - Exception raised if when updating the password,
57
57
  the old password does not match.
58
58
  """ # noqa: D205
59
59
 
@@ -1,10 +1,11 @@
1
- """Fixtures - To populate the database with pre-created data.
1
+ """Ramifice - Fixtures - To populate the database with pre-created data.
2
2
 
3
3
  Runs automatically during Model migration.
4
4
  """
5
5
 
6
6
  __all__ = ("apply_fixture",)
7
7
 
8
+ import logging
8
9
  from datetime import datetime
9
10
  from typing import Any
10
11
 
@@ -15,13 +16,15 @@ from termcolor import colored
15
16
 
16
17
  from ramifice.utils.errors import PanicError
17
18
 
19
+ logger = logging.getLogger(__name__)
20
+
18
21
 
19
22
  async def apply_fixture(
20
23
  fixture_name: str,
21
24
  cls_model: Any,
22
25
  collection: AsyncCollection,
23
26
  ) -> None:
24
- """Apply fixture for current Model.
27
+ """Ramifice - Apply fixture for current Model.
25
28
 
26
29
  Runs automatically during Model migration.
27
30
  """
@@ -37,6 +40,7 @@ async def apply_fixture(
37
40
  + f"META param: `fixture_name` ({fixture_name}) => "
38
41
  + "It seems that fixture is empty or it has incorrect contents!"
39
42
  )
43
+ logger.error(msg)
40
44
  raise PanicError(msg)
41
45
 
42
46
  if data_yaml is not None:
@@ -71,6 +75,7 @@ async def apply_fixture(
71
75
  print(colored(fixture_path, "blue", attrs=["bold"]))
72
76
  inst_model.print_err()
73
77
  msg = f"Fixture `{fixture_name}` failed."
78
+ logger.error(msg)
74
79
  raise PanicError(msg)
75
80
  # Get data for document.
76
81
  checked_data: dict[str, Any] = result_check["data"]
@@ -1,4 +1,4 @@
1
- """Migration are `Ramifice` way of
1
+ """Ramifice - Migration are `Ramifice` way of
2
2
  propagating changes you make to
3
3
  your models (add or delete a Model, add or delete a field in Model, etc.) into
4
4
  your database schema.
@@ -6,6 +6,7 @@ your database schema.
6
6
 
7
7
  __all__ = ("Migration",)
8
8
 
9
+ import logging
9
10
  from datetime import datetime
10
11
  from typing import Any
11
12
 
@@ -18,16 +19,21 @@ from ramifice.utils import constants
18
19
  from ramifice.utils.errors import DoesNotMatchRegexError, NoModelsForMigrationError, PanicError
19
20
  from ramifice.utils.fixtures import apply_fixture
20
21
 
22
+ logger = logging.getLogger(__name__)
23
+
21
24
 
22
25
  class Migration:
23
- """Migration of models to database."""
26
+ """Ramifice - Migration of models to database."""
24
27
 
25
28
  def __init__(self, database_name: str, mongo_client: AsyncMongoClient): # noqa: D107
26
29
  constants.DEBUG = False
27
30
  #
28
31
  db_name_regex = constants.REGEX["database_name"]
29
32
  if db_name_regex.match(database_name) is None:
30
- raise DoesNotMatchRegexError("^[a-zA-Z][-_a-zA-Z0-9]{0,59}$")
33
+ regex_str: str = "^[a-zA-Z][-_a-zA-Z0-9]{0,59}$"
34
+ msg: str = f"Does not match the regular expression: {regex_str}"
35
+ logger.error(msg)
36
+ raise DoesNotMatchRegexError(regex_str)
31
37
  #
32
38
  constants.DATABASE_NAME = database_name
33
39
  constants.MONGO_CLIENT = mongo_client
@@ -36,10 +42,11 @@ class Migration:
36
42
  self.model_list: list[Any] = Model.__subclasses__()
37
43
  # Raise the exception if there are no models for migration.
38
44
  if len(self.model_list) == 0:
45
+ logger.error("No Models for Migration!")
39
46
  raise NoModelsForMigrationError() # type: ignore[no-untyped-call]
40
47
 
41
48
  async def reset(self) -> None:
42
- """Reset the condition of the models in a super collection.
49
+ """Ramifice - Reset the condition of the models in a super collection.
43
50
 
44
51
  Switch the `is_model_exist` parameter in the condition `False`.
45
52
  """
@@ -55,7 +62,7 @@ class Migration:
55
62
  await super_collection.update_one(q_filter, update)
56
63
 
57
64
  async def model_state(self, metadata: dict[str, Any]) -> dict[str, Any]:
58
- """Get the state of the current model from a super collection."""
65
+ """Ramifice - Get the state of the current model from a super collection."""
59
66
  # Get access to super collection.
60
67
  # (Contains Model state and dynamic field data.)
61
68
  super_collection: AsyncCollection = constants.MONGO_DATABASE[
@@ -79,7 +86,7 @@ class Migration:
79
86
  return model_state
80
87
 
81
88
  def new_fields(self, metadata: dict[str, Any], model_state: dict[str, Any]) -> list[str]:
82
- """Get a list of new fields that were added to Model."""
89
+ """Ramifice - Get a list of new fields that were added to Model."""
83
90
  new_fields: list[str] = []
84
91
  for field_name, field_type in metadata["field_name_and_type"].items():
85
92
  old_field_type: str | None = model_state["field_name_and_type"].get(field_name)
@@ -88,7 +95,7 @@ class Migration:
88
95
  return new_fields
89
96
 
90
97
  async def napalm(self) -> None:
91
- """Delete data for non-existent Models from a super collection,
98
+ """Ramifice - Delete data for non-existent Models from a super collection,
92
99
  delete collections associated with those Models.
93
100
  """ # noqa: D205
94
101
  # Get access to database.
@@ -109,7 +116,7 @@ class Migration:
109
116
  await database.drop_collection(collection_name) # type: ignore[union-attr]
110
117
 
111
118
  async def migrate(self) -> None:
112
- """Run migration process.
119
+ """Ramifice - Run migration process.
113
120
 
114
121
  1) Update the state of Models in the super collection.
115
122
  2) Register new Models in the super collection.
@@ -167,7 +174,9 @@ class Migration:
167
174
  if not result_check["is_valid"]:
168
175
  print(colored("\n!!!>>MIGRATION<<!!!", "red", attrs=["bold"]))
169
176
  inst_model.print_err()
170
- raise PanicError("Migration failed.")
177
+ msg: str = "Migration failed."
178
+ logger.error(msg)
179
+ raise PanicError(msg)
171
180
  # Get checked data.
172
181
  checked_data = result_check["data"]
173
182
  # Add password from mongo_doc to checked_data.
@@ -1,4 +1,4 @@
1
- """A set of mixins for Ramifice."""
1
+ """Ramifice - Set of mixins for Models and Fields."""
2
2
 
3
3
  from ramifice.utils.mixins.add_valid import AddValidMixin
4
4
  from ramifice.utils.mixins.hooks import HooksMixin
@@ -1,4 +1,4 @@
1
- """AddValidMixin - Contains an abstract method for additional validation of fields."""
1
+ """Ramifice - AddValidMixin - Contains an abstract method for additional validation of fields."""
2
2
 
3
3
  __all__ = ("AddValidMixin",)
4
4
 
@@ -6,9 +6,9 @@ from abc import ABCMeta
6
6
 
7
7
 
8
8
  class AddValidMixin(metaclass=ABCMeta):
9
- """Contains an abstract method for additional validation of fields."""
9
+ """Ramifice - Contains an abstract method for additional validation of fields."""
10
10
 
11
11
  async def add_validation(self) -> dict[str, str]:
12
- """Additional validation of fields."""
12
+ """Ramifice - Additional validation of fields."""
13
13
  error_map: dict[str, str] = {}
14
14
  return error_map
@@ -1,4 +1,4 @@
1
- """HooksMixin - Contains abstract methods for creating hooks."""
1
+ """Ramifice - HooksMixin - Contains abstract methods for creating hooks."""
2
2
 
3
3
  __all__ = ("HooksMixin",)
4
4
 
@@ -6,22 +6,22 @@ from abc import ABCMeta
6
6
 
7
7
 
8
8
  class HooksMixin(metaclass=ABCMeta):
9
- """A set of abstract methods for creating hooks."""
9
+ """Ramifice - A set of abstract methods for creating hooks."""
10
10
 
11
11
  async def pre_create(self) -> None:
12
- """Called before a new document is created in the database."""
12
+ """Ramifice - Called before a new document is created in the database."""
13
13
 
14
14
  async def post_create(self) -> None:
15
- """Called after a new document has been created in the database."""
15
+ """Ramifice - Called after a new document has been created in the database."""
16
16
 
17
17
  async def pre_update(self) -> None:
18
- """Called before updating an existing document in the database."""
18
+ """Ramifice - Called before updating an existing document in the database."""
19
19
 
20
20
  async def post_update(self) -> None:
21
- """Called after an existing document in the database is updated."""
21
+ """Ramifice - Called after an existing document in the database is updated."""
22
22
 
23
23
  async def pre_delete(self) -> None:
24
- """Called before deleting an existing document in the database."""
24
+ """Ramifice - Called before deleting an existing document in the database."""
25
25
 
26
26
  async def post_delete(self) -> None:
27
- """Called after an existing document in the database has been deleted."""
27
+ """Ramifice - Called after an existing document in the database has been deleted."""
@@ -1,4 +1,4 @@
1
- """IndexMixin - Contains abstract method for indexing the model in the database."""
1
+ """Ramifice - IndexMixin - Contains abstract method for indexing the model in the database."""
2
2
 
3
3
  __all__ = ("IndexMixin",)
4
4
 
@@ -6,8 +6,8 @@ from abc import ABCMeta
6
6
 
7
7
 
8
8
  class IndexMixin(metaclass=ABCMeta):
9
- """Contains the method for indexing the model in the database."""
9
+ """Ramifice - Contains the method for indexing the model in the database."""
10
10
 
11
11
  @classmethod
12
12
  async def indexing(cls) -> None:
13
- """For set up and start indexing."""
13
+ """Ramifice - Set up and start indexing."""
@@ -1,4 +1,4 @@
1
- """JsonMixin - Contains the methods for converting Fields to JSON and back."""
1
+ """Ramifice - JsonMixin - Contains the methods for converting Fields to JSON and back."""
2
2
 
3
3
  __all__ = ("JsonMixin",)
4
4
 
@@ -8,10 +8,10 @@ import orjson
8
8
 
9
9
 
10
10
  class JsonMixin:
11
- """Contains the methods for converting Fields to JSON and back."""
11
+ """Ramifice - Contains the methods for converting Fields to JSON and back."""
12
12
 
13
13
  def to_dict(self) -> dict[str, Any]:
14
- """Convert object instance to a dictionary."""
14
+ """Ramifice - Convert object instance to a dictionary."""
15
15
  json_dict: dict[str, Any] = {}
16
16
  for name, data in self.__dict__.items():
17
17
  if not callable(data):
@@ -19,12 +19,12 @@ class JsonMixin:
19
19
  return json_dict
20
20
 
21
21
  def to_json(self) -> str:
22
- """Convert object instance to a JSON string."""
22
+ """Ramifice - Convert object instance to a JSON string."""
23
23
  return orjson.dumps(self.to_dict()).decode("utf-8")
24
24
 
25
25
  @classmethod
26
26
  def from_dict(cls, json_dict: dict[str, Any]) -> Any:
27
- """Convert JSON string to a object instance."""
27
+ """Ramifice - Convert JSON string to a object instance."""
28
28
  obj = cls()
29
29
  for name, data in json_dict.items():
30
30
  obj.__dict__[name] = data
@@ -32,6 +32,6 @@ class JsonMixin:
32
32
 
33
33
  @classmethod
34
34
  def from_json(cls, json_str: str) -> Any:
35
- """Convert JSON string to a object instance."""
35
+ """Ramifice - Convert JSON string to a object instance."""
36
36
  json_dict = orjson.loads(json_str)
37
37
  return cls.from_dict(json_dict)