ramifice 0.8.10__py3-none-any.whl → 0.8.12__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 +58 -51
  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 +36 -35
  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 +8 -4
  79. ramifice/utils/unit.py +8 -3
  80. {ramifice-0.8.10.dist-info → ramifice-0.8.12.dist-info}/METADATA +1 -1
  81. ramifice-0.8.12.dist-info/RECORD +84 -0
  82. ramifice-0.8.10.dist-info/RECORD +0 -84
  83. {ramifice-0.8.10.dist-info → ramifice-0.8.12.dist-info}/WHEEL +0 -0
  84. {ramifice-0.8.10.dist-info → ramifice-0.8.12.dist-info}/licenses/LICENSE +0 -0
@@ -1,4 +1,4 @@
1
- """Group for checking id fields.
1
+ """Ramifice - Group for checking id fields.
2
2
 
3
3
  Supported fields:
4
4
  IDField
@@ -15,14 +15,14 @@ from ramifice.utils import translations
15
15
 
16
16
 
17
17
  class IDGroupMixin:
18
- """Group for checking id fields.
18
+ """Ramifice - Group for checking id fields.
19
19
 
20
20
  Supported fields:
21
21
  IDField
22
22
  """
23
23
 
24
24
  def id_group(self, params: dict[str, Any]) -> None:
25
- """Checking id fields."""
25
+ """Ramifice - Checking id fields."""
26
26
  field = params["field_data"]
27
27
  # Get current value.
28
28
  value = field.value
@@ -1,4 +1,4 @@
1
- """Group for checking image fields.
1
+ """Ramifice - Group for checking image fields.
2
2
 
3
3
  Supported fields: ImageField
4
4
  """
@@ -16,13 +16,13 @@ from ramifice.utils.tools import to_human_size
16
16
 
17
17
 
18
18
  class ImgGroupMixin:
19
- """Group for checking image fields.
19
+ """Ramifice - Group for checking image fields.
20
20
 
21
21
  Supported fields: ImageField
22
22
  """
23
23
 
24
24
  async def img_group(self, params: dict[str, Any]) -> None:
25
- """Checking image fields."""
25
+ """Ramifice - Checking image fields."""
26
26
  field = params["field_data"]
27
27
  value = field.value or None
28
28
 
@@ -92,38 +92,39 @@ class ImgGroupMixin:
92
92
  continue
93
93
  size = max_size, max_size
94
94
  img.thumbnail(size=size, resample=Image.Resampling.LANCZOS)
95
- if size_name == "lg":
96
- value["path_lg"] = f"{imgs_dir_path}/lg{extension}"
97
- value["url_lg"] = f"{imgs_dir_url}/lg{extension}"
98
- await to_thread(
99
- img.save,
100
- fp=value["path_lg"],
101
- format=ext_upper,
102
- )
103
- elif size_name == "md":
104
- value["path_md"] = f"{imgs_dir_path}/md{extension}"
105
- value["url_md"] = f"{imgs_dir_url}/md{extension}"
106
- await to_thread(
107
- img.save,
108
- fp=value["path_md"],
109
- format=ext_upper,
110
- )
111
- elif size_name == "sm":
112
- value["path_sm"] = f"{imgs_dir_path}/sm{extension}"
113
- value["url_sm"] = f"{imgs_dir_url}/sm{extension}"
114
- await to_thread(
115
- img.save,
116
- fp=value["path_sm"],
117
- format=ext_upper,
118
- )
119
- elif size_name == "xs":
120
- value["path_xs"] = f"{imgs_dir_path}/xs{extension}"
121
- value["url_xs"] = f"{imgs_dir_url}/xs{extension}"
122
- await to_thread(
123
- img.save,
124
- fp=value["path_xs"],
125
- format=ext_upper,
126
- )
95
+ match size_name:
96
+ case "lg":
97
+ value["path_lg"] = f"{imgs_dir_path}/lg{extension}"
98
+ value["url_lg"] = f"{imgs_dir_url}/lg{extension}"
99
+ await to_thread(
100
+ img.save,
101
+ fp=value["path_lg"],
102
+ format=ext_upper,
103
+ )
104
+ case "md":
105
+ value["path_md"] = f"{imgs_dir_path}/md{extension}"
106
+ value["url_md"] = f"{imgs_dir_url}/md{extension}"
107
+ await to_thread(
108
+ img.save,
109
+ fp=value["path_md"],
110
+ format=ext_upper,
111
+ )
112
+ case "sm":
113
+ value["path_sm"] = f"{imgs_dir_path}/sm{extension}"
114
+ value["url_sm"] = f"{imgs_dir_url}/sm{extension}"
115
+ await to_thread(
116
+ img.save,
117
+ fp=value["path_sm"],
118
+ format=ext_upper,
119
+ )
120
+ case "xs":
121
+ value["path_xs"] = f"{imgs_dir_path}/xs{extension}"
122
+ value["url_xs"] = f"{imgs_dir_url}/xs{extension}"
123
+ await to_thread(
124
+ img.save,
125
+ fp=value["path_xs"],
126
+ format=ext_upper,
127
+ )
127
128
  # Insert result.
128
129
  if params["is_save"] and (value["is_new_img"] or value["save_as_is"]):
129
130
  value["is_delete"] = False
@@ -1,4 +1,4 @@
1
- """Group for checking integer fields.
1
+ """Ramifice - Group for checking integer fields.
2
2
 
3
3
  Supported fields:
4
4
  IntegerField | FloatField
@@ -17,14 +17,14 @@ from ramifice.utils import translations
17
17
 
18
18
 
19
19
  class NumGroupMixin:
20
- """Group for checking integer fields.
20
+ """Ramifice - Group for checking integer fields.
21
21
 
22
22
  Supported fields:
23
23
  IntegerField | FloatField
24
24
  """
25
25
 
26
26
  async def num_group(self, params: dict[str, Any]) -> None:
27
- """Checking number fields."""
27
+ """Ramifice - Checking number fields."""
28
28
  field = params["field_data"]
29
29
  field_name = field.name
30
30
  # Get current value.
@@ -1,4 +1,4 @@
1
- """Group for checking password fields.
1
+ """Ramifice - Group for checking password fields.
2
2
 
3
3
  Supported fields: PasswordField
4
4
  """
@@ -15,13 +15,13 @@ from ramifice.utils.tools import is_password
15
15
 
16
16
 
17
17
  class PassGroupMixin:
18
- """Group for checking password fields.
18
+ """Ramifice - Group for checking password fields.
19
19
 
20
20
  Supported fields: PasswordField
21
21
  """
22
22
 
23
23
  def pass_group(self, params: dict[str, Any]) -> None:
24
- """Checking password fields."""
24
+ """Ramifice - Checking password fields."""
25
25
  field = params["field_data"]
26
26
  # When updating the document, skip the verification.
27
27
  if params["is_update"]:
@@ -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"]