ramifice 0.8.25__py3-none-any.whl → 0.8.27__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 (58) hide show
  1. ramifice/commons/tools.py +1 -5
  2. ramifice/fields/bool_field.py +13 -3
  3. ramifice/fields/choice_float_dyn_field.py +11 -1
  4. ramifice/fields/choice_float_field.py +15 -3
  5. ramifice/fields/choice_float_mult_dyn_field.py +11 -1
  6. ramifice/fields/choice_float_mult_field.py +15 -3
  7. ramifice/fields/choice_int_dyn_field.py +11 -1
  8. ramifice/fields/choice_int_field.py +15 -3
  9. ramifice/fields/choice_int_mult_dyn_field.py +11 -1
  10. ramifice/fields/choice_int_mult_field.py +15 -3
  11. ramifice/fields/choice_text_dyn_field.py +11 -1
  12. ramifice/fields/choice_text_field.py +15 -3
  13. ramifice/fields/choice_text_mult_dyn_field.py +11 -1
  14. ramifice/fields/choice_text_mult_field.py +15 -3
  15. ramifice/fields/color_field.py +20 -7
  16. ramifice/fields/date_field.py +19 -4
  17. ramifice/fields/date_time_field.py +19 -4
  18. ramifice/fields/email_field.py +19 -5
  19. ramifice/fields/file_field.py +24 -11
  20. ramifice/fields/float_field.py +22 -4
  21. ramifice/fields/general/choice_group.py +1 -3
  22. ramifice/fields/general/date_group.py +1 -2
  23. ramifice/fields/general/field.py +2 -4
  24. ramifice/fields/general/file_group.py +1 -3
  25. ramifice/fields/general/number_group.py +1 -3
  26. ramifice/fields/general/text_group.py +1 -3
  27. ramifice/fields/id_field.py +13 -8
  28. ramifice/fields/image_field.py +25 -15
  29. ramifice/fields/integer_field.py +22 -4
  30. ramifice/fields/ip_field.py +19 -5
  31. ramifice/fields/password_field.py +14 -5
  32. ramifice/fields/phone_field.py +19 -5
  33. ramifice/fields/slug_field.py +14 -3
  34. ramifice/fields/text_field.py +20 -3
  35. ramifice/fields/url_field.py +15 -15
  36. ramifice/models/__init__.py +7 -1
  37. ramifice/models/decorator.py +2 -2
  38. ramifice/models/model.py +5 -7
  39. ramifice/paladins/__init__.py +16 -1
  40. ramifice/paladins/add_valid.py +3 -2
  41. ramifice/paladins/check.py +5 -5
  42. ramifice/paladins/groups/slug_group.py +1 -1
  43. ramifice/paladins/groups/text_group.py +2 -2
  44. ramifice/paladins/hooks.py +8 -2
  45. ramifice/paladins/indexing.py +3 -2
  46. ramifice/paladins/save.py +2 -2
  47. ramifice/paladins/validation.py +9 -9
  48. ramifice/utils/constants.py +1 -1
  49. ramifice/utils/fixtures.py +3 -3
  50. ramifice/utils/migration.py +3 -3
  51. ramifice/utils/tools.py +1 -1
  52. ramifice/utils/translations.py +1 -1
  53. ramifice/utils/unit.py +2 -2
  54. {ramifice-0.8.25.dist-info → ramifice-0.8.27.dist-info}/METADATA +2 -3
  55. ramifice-0.8.27.dist-info/RECORD +83 -0
  56. ramifice-0.8.25.dist-info/RECORD +0 -83
  57. {ramifice-0.8.25.dist-info → ramifice-0.8.27.dist-info}/WHEEL +0 -0
  58. {ramifice-0.8.25.dist-info → ramifice-0.8.27.dist-info}/licenses/LICENSE +0 -0
@@ -14,18 +14,36 @@ logger = logging.getLogger(__name__)
14
14
 
15
15
 
16
16
  class FloatField(Field, NumberGroup, JsonMixin):
17
- """Field of Model for enter (float) number."""
17
+ """Field of Model for enter (float) number.
18
+
19
+ Agrs:
20
+ label: Text label for a web form field.
21
+ placeholder: Displays prompt text.
22
+ default: Value by default.
23
+ hide: Hide field from user.
24
+ disabled: Blocks access and modification of the element.
25
+ ignored: If true, the value of this field is not saved in the database.
26
+ hint: An alternative for the `placeholder` parameter.
27
+ warning: Warning information.
28
+ required: Required field.
29
+ readonly: Specifies that the field cannot be modified by the user.
30
+ unique: The unique value of a field in a collection.
31
+ max_number: Maximum allowed number.
32
+ min_number: Minimum allowed number.
33
+ step: Increment step for numeric fields.
34
+ input_type: Field type - `number` or `range`.
35
+ """
18
36
 
19
37
  def __init__( # noqa: D107
20
38
  self,
21
39
  label: str = "",
22
- disabled: bool = False,
40
+ placeholder: str = "",
41
+ default: float | None = None,
23
42
  hide: bool = False,
43
+ disabled: bool = False,
24
44
  ignored: bool = False,
25
45
  hint: str = "",
26
46
  warning: list[str] | None = None,
27
- default: float | None = None,
28
- placeholder: str = "",
29
47
  required: bool = False,
30
48
  readonly: bool = False,
31
49
  unique: bool = False,
@@ -2,10 +2,8 @@
2
2
 
3
3
  __all__ = ("ChoiceGroup",)
4
4
 
5
- from abc import ABCMeta
6
5
 
7
-
8
- class ChoiceGroup(metaclass=ABCMeta):
6
+ class ChoiceGroup: # noqa: B903
9
7
  """General additional parameters for choice fields.
10
8
 
11
9
  Args:
@@ -2,11 +2,10 @@
2
2
 
3
3
  __all__ = ("DateGroup",)
4
4
 
5
- from abc import ABCMeta
6
5
  from datetime import datetime
7
6
 
8
7
 
9
- class DateGroup(metaclass=ABCMeta):
8
+ class DateGroup:
10
9
  """General additional parameters for date|datetime fields.
11
10
 
12
11
  Args:
@@ -2,10 +2,8 @@
2
2
 
3
3
  __all__ = ("Field",)
4
4
 
5
- from abc import ABCMeta
6
5
 
7
-
8
- class Field(metaclass=ABCMeta):
6
+ class Field:
9
7
  """General parameters for all types fields of Model.
10
8
 
11
9
  Args:
@@ -28,7 +26,7 @@ class Field(metaclass=ABCMeta):
28
26
  ignored: bool = False,
29
27
  hint: str = "",
30
28
  warning: list[str] | None = None,
31
- errors: list[str] = [],
29
+ errors: list[str] = [], # noqa: B006
32
30
  field_type: str = "",
33
31
  group: str = "",
34
32
  ) -> None:
@@ -2,10 +2,8 @@
2
2
 
3
3
  __all__ = ("FileGroup",)
4
4
 
5
- from abc import ABCMeta
6
5
 
7
-
8
- class FileGroup(metaclass=ABCMeta):
6
+ class FileGroup:
9
7
  """General additional parameters for file fields.
10
8
 
11
9
  Args:
@@ -2,10 +2,8 @@
2
2
 
3
3
  __all__ = ("NumberGroup",)
4
4
 
5
- from abc import ABCMeta
6
5
 
7
-
8
- class NumberGroup(metaclass=ABCMeta):
6
+ class NumberGroup: # noqa: B903
9
7
  """General additional parameters for number fields.
10
8
 
11
9
  Args:
@@ -2,10 +2,8 @@
2
2
 
3
3
  __all__ = ("TextGroup",)
4
4
 
5
- from abc import ABCMeta
6
5
 
7
-
8
- class TextGroup(metaclass=ABCMeta):
6
+ class TextGroup:
9
7
  """General additional parameters for text fields.
10
8
 
11
9
  Args:
@@ -17,23 +17,28 @@ logger = logging.getLogger(__name__)
17
17
  class IDField(Field):
18
18
  """Field of Model for enter identifier of document.
19
19
 
20
- Attributes:
21
- input_type -- Input type for a web form field.
22
- placeholder -- Displays prompt text.
23
- required -- Required field.
24
- readonly -- Specifies that the field cannot be modified by the user.
25
- unique -- The unique value of a field in a collection.
20
+ Agrs:
21
+ label: Text label for a web form field.
22
+ placeholder: Displays prompt text.
23
+ hide: Hide field from user.
24
+ disabled: Blocks access and modification of the element.
25
+ ignored: If true, the value of this field is not saved in the database.
26
+ hint: An alternative for the `placeholder` parameter.
27
+ warning: Warning information.
28
+ required: Required field.
29
+ readonly: Specifies that the field cannot be modified by the user.
30
+ unique: The unique value of a field in a collection.
26
31
  """
27
32
 
28
33
  def __init__( # noqa: D107
29
34
  self,
30
35
  label: str = "",
31
- disabled: bool = False,
36
+ placeholder: str = "",
32
37
  hide: bool = False,
38
+ disabled: bool = False,
33
39
  ignored: bool = False,
34
40
  hint: str = "",
35
41
  warning: list[str] | None = None,
36
- placeholder: str = "",
37
42
  required: bool = False,
38
43
  readonly: bool = False,
39
44
  unique: bool = False,
@@ -5,7 +5,7 @@ __all__ = ("ImageField",)
5
5
  import logging
6
6
  import uuid
7
7
  from base64 import b64decode
8
- from datetime import date
8
+ from datetime import datetime
9
9
  from os import makedirs
10
10
  from os.path import basename, exists, getsize
11
11
  from shutil import copyfile
@@ -23,25 +23,40 @@ logger = logging.getLogger(__name__)
23
23
 
24
24
 
25
25
  class ImageField(Field, FileGroup, JsonMixin):
26
- """Field of Model for upload image."""
26
+ """Field of Model for upload image.
27
+
28
+ Agrs:
29
+ label: Text label for a web form field.
30
+ placeholder: Displays prompt text.
31
+ default: Value by default.
32
+ hide: Hide field from user.
33
+ disabled: Blocks access and modification of the element.
34
+ ignored: If true, the value of this field is not saved in the database.
35
+ hint: An alternative for the `placeholder` parameter.
36
+ warning: Warning information.
37
+ required: Required field.
38
+ max_size: The maximum allowed file size in bytes.
39
+ target_dir: Directory for files inside media directory.
40
+ accept: Describing which file types to allow. Example: "image/png,image/jpeg,image/webp".
41
+ thumbnails: Sizes of thumbnails - Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }.
42
+ """
27
43
 
28
44
  def __init__( # noqa: D107
29
45
  self,
30
46
  label: str = "",
31
- disabled: bool = False,
47
+ placeholder: str = "",
48
+ default: str | None = None,
32
49
  hide: bool = False,
50
+ disabled: bool = False,
33
51
  ignored: bool = False,
34
52
  hint: str = "",
35
53
  warning: list[str] | None = None,
36
54
  required: bool = False,
37
55
  # The maximum size of the original image in bytes.
38
56
  max_size: int = 2097152, # 2 MB = 2097152 Bytes (in binary)
39
- default: str | None = None,
40
- placeholder: str = "",
41
57
  target_dir: str = "images",
42
58
  accept: str = "image/png,image/jpeg,image/webp",
43
59
  # Available 4 sizes from lg to xs or None.
44
- # Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
45
60
  thumbnails: dict[str, int] | None = None,
46
61
  ) -> None:
47
62
  if constants.DEBUG:
@@ -50,16 +65,12 @@ class ImageField(Field, FileGroup, JsonMixin):
50
65
  if not isinstance(default, str):
51
66
  raise AssertionError("Parameter `default` - Not а `str` type!")
52
67
  if len(default) == 0:
53
- raise AssertionError(
54
- "The `default` parameter should not contain an empty string!"
55
- )
68
+ raise AssertionError("The `default` parameter should not contain an empty string!")
56
69
  if thumbnails is not None:
57
70
  if not isinstance(thumbnails, dict):
58
71
  raise AssertionError("Parameter `thumbnails` - Not а `dict` type!")
59
72
  if len(thumbnails) == 0:
60
- raise AssertionError(
61
- "The `thumbnails` parameter should not contain an empty dictionary!"
62
- )
73
+ raise AssertionError("The `thumbnails` parameter should not contain an empty dictionary!")
63
74
  size_name_list = ["lg", "md", "sm", "xs"]
64
75
  curr_size_thumb: int = 0
65
76
  for size_name in thumbnails.keys():
@@ -130,7 +141,6 @@ class ImageField(Field, FileGroup, JsonMixin):
130
141
 
131
142
  self.value: dict[str, str | int | bool] | None = None
132
143
  # Available 4 sizes from lg to xs or None.
133
- # Example: {"lg": 1200, "md": 600, "sm": 300, "xs": 150 }
134
144
  self.thumbnails = thumbnails
135
145
 
136
146
  async def from_base64(
@@ -163,7 +173,7 @@ class ImageField(Field, FileGroup, JsonMixin):
163
173
  if item[0] == 40:
164
174
  break
165
175
  # Create the current date for the directory name.
166
- date_str: str = str(date.today())
176
+ date_str: str = str(datetime.now().date()) # noqa: DTZ005
167
177
  # Directory name for the original image and its thumbnails.
168
178
  general_dir = uuid.uuid4()
169
179
  # Create path to target directory with images.
@@ -222,7 +232,7 @@ class ImageField(Field, FileGroup, JsonMixin):
222
232
  logger.error(msg)
223
233
  raise FileHasNoExtensionError(msg)
224
234
  # Create the current date for the directory name.
225
- date_str: str = str(date.today())
235
+ date_str: str = str(datetime.now().date()) # noqa: DTZ005
226
236
  # Directory name for the original image and its thumbnails.
227
237
  general_dir = uuid.uuid4()
228
238
  # Create path to target directory with images.
@@ -14,18 +14,36 @@ logger = logging.getLogger(__name__)
14
14
 
15
15
 
16
16
  class IntegerField(Field, NumberGroup, JsonMixin):
17
- """Field of Model for enter (int) number."""
17
+ """Field of Model for enter (int) number.
18
+
19
+ Agrs:
20
+ label: Text label for a web form field.
21
+ placeholder: Displays prompt text.
22
+ default: Value by default.
23
+ hide: Hide field from user.
24
+ disabled: Blocks access and modification of the element.
25
+ ignored: If true, the value of this field is not saved in the database.
26
+ hint: An alternative for the `placeholder` parameter.
27
+ warning: Warning information.
28
+ required: Required field.
29
+ readonly: Specifies that the field cannot be modified by the user.
30
+ unique: The unique value of a field in a collection.
31
+ max_number: Maximum allowed number.
32
+ min_number: Minimum allowed number.
33
+ step: Increment step for numeric fields.
34
+ input_type: Field type - `number` or `range`.
35
+ """
18
36
 
19
37
  def __init__( # noqa: D107
20
38
  self,
21
39
  label: str = "",
22
- disabled: bool = False,
40
+ placeholder: str = "",
41
+ default: int | None = None,
23
42
  hide: bool = False,
43
+ disabled: bool = False,
24
44
  ignored: bool = False,
25
45
  hint: str = "",
26
46
  warning: list[str] | None = None,
27
- default: int | None = None,
28
- placeholder: str = "",
29
47
  required: bool = False,
30
48
  readonly: bool = False,
31
49
  unique: bool = False,
@@ -14,18 +14,32 @@ logger = logging.getLogger(__name__)
14
14
 
15
15
 
16
16
  class IPField(Field, TextGroup, JsonMixin):
17
- """Field of Model for enter IP address."""
17
+ """Field of Model for enter IP address.
18
+
19
+ Agrs:
20
+ label: Text label for a web form field.
21
+ placeholder: Displays prompt text.
22
+ default: Value by default.
23
+ hide: Hide field from user.
24
+ disabled: Blocks access and modification of the element.
25
+ ignored: If true, the value of this field is not saved in the database.
26
+ hint: An alternative for the `placeholder` parameter.
27
+ warning: Warning information.
28
+ required: Required field.
29
+ readonly: Specifies that the field cannot be modified by the user.
30
+ unique: The unique value of a field in a collection.
31
+ """
18
32
 
19
33
  def __init__( # noqa: D107
20
34
  self,
21
35
  label: str = "",
22
- disabled: bool = False,
36
+ placeholder: str = "",
37
+ default: str | None = None,
23
38
  hide: bool = False,
39
+ disabled: bool = False,
24
40
  ignored: bool = False,
25
41
  hint: str = "",
26
42
  warning: list[str] | None = None,
27
- default: str | None = None,
28
- placeholder: str = "",
29
43
  required: bool = False,
30
44
  readonly: bool = False,
31
45
  unique: bool = False,
@@ -42,7 +56,7 @@ class IPField(Field, TextGroup, JsonMixin):
42
56
  try:
43
57
  ipaddress.ip_address(default)
44
58
  except ValueError:
45
- raise AssertionError("Parameter `default` - Invalid IP address!")
59
+ raise AssertionError("Parameter `default` - Invalid IP address!") # noqa: B904
46
60
  if not isinstance(label, str):
47
61
  raise AssertionError("Parameter `default` - Not а `str` type!")
48
62
  if not isinstance(disabled, bool):
@@ -16,20 +16,29 @@ logger = logging.getLogger(__name__)
16
16
  class PasswordField(Field):
17
17
  r"""Field of Model for enter password.
18
18
 
19
- Warning:
20
- Regular expression: ^[-._!"`'#%&,:;<>=@{}~$()*+/\\?[]^|a-zA-Z0-9]{8,256}$
21
- Valid characters: a-z A-Z 0-9 - . _ ! " ` ' # % & , : ; < > = @ { } ~ $ ( ) * + / \\ ? [ ] ^ |
22
- Number of characters: from 8 to 256.
19
+ Attention:
20
+ - Regular expression: ^[-._!"`'#%&,:;<>=@{}~$()*+/\\?[]^|a-zA-Z0-9]{8,256}$
21
+ - Valid characters: a-z A-Z 0-9 - . _ ! " ` ' # % & , : ; < > = @ { } ~ $ ( ) * + / \\ ? [ ] ^ |
22
+ - Number of characters: from 8 to 256.
23
+
24
+ Agrs:
25
+ label: Text label for a web form field.
26
+ placeholder: Displays prompt text.
27
+ hide: Hide field from user.
28
+ ignored: If true, the value of this field is not saved in the database.
29
+ hint: An alternative for the `placeholder` parameter.
30
+ warning: Warning information.
31
+ required: Required field.
23
32
  """
24
33
 
25
34
  def __init__( # noqa: D107
26
35
  self,
27
36
  label: str = "",
37
+ placeholder: str = "",
28
38
  hide: bool = False,
29
39
  ignored: bool = False,
30
40
  hint: str = "",
31
41
  warning: list[str] | None = None,
32
- placeholder: str = "",
33
42
  required: bool = False,
34
43
  ) -> None:
35
44
  if constants.DEBUG:
@@ -17,19 +17,33 @@ logger = logging.getLogger(__name__)
17
17
  class PhoneField(Field, TextGroup, JsonMixin):
18
18
  """Field of Model for enter phone number.
19
19
 
20
- WARNING: By default is used validator `phonenumbers.is_valid_number()`.
20
+ Attention:
21
+ By default is used validator `phonenumbers.is_valid_number()`.
22
+
23
+ Agrs:
24
+ label: Text label for a web form field.
25
+ placeholder: Displays prompt text.
26
+ default: Value by default.
27
+ hide: Hide field from user.
28
+ disabled: Blocks access and modification of the element.
29
+ ignored: If true, the value of this field is not saved in the database.
30
+ hint: An alternative for the `placeholder` parameter.
31
+ warning: Warning information.
32
+ required: Required field.
33
+ readonly: Specifies that the field cannot be modified by the user.
34
+ unique: The unique value of a field in a collection.
21
35
  """
22
36
 
23
37
  def __init__( # noqa: D107
24
38
  self,
25
39
  label: str = "",
26
- disabled: bool = False,
40
+ placeholder: str = "",
41
+ default: str | None = None,
27
42
  hide: bool = False,
43
+ disabled: bool = False,
28
44
  ignored: bool = False,
29
45
  hint: str = "",
30
46
  warning: list[str] | None = None,
31
- default: str | None = None,
32
- placeholder: str = "",
33
47
  required: bool = False,
34
48
  readonly: bool = False,
35
49
  unique: bool = False,
@@ -48,7 +62,7 @@ class PhoneField(Field, TextGroup, JsonMixin):
48
62
  if not phonenumbers.is_valid_number(phone_default):
49
63
  raise AssertionError()
50
64
  except phonenumbers.phonenumberutil.NumberParseException:
51
- raise AssertionError("Parameter `default` - Invalid Phone number!")
65
+ raise AssertionError("Parameter `default` - Invalid Phone number!") # noqa: B904
52
66
  if not isinstance(label, str):
53
67
  raise AssertionError("Parameter `default` - Not а `str` type!")
54
68
  if not isinstance(disabled, bool):
@@ -16,19 +16,30 @@ class SlugField(Field, TextGroup, JsonMixin):
16
16
  """Field of Model for automatic generation of string `slug`.
17
17
 
18
18
  Convenient to use for Url addresses.
19
+
20
+ Agrs:
21
+ label: Text label for a web form field.
22
+ placeholder: Displays prompt text.
23
+ hide: Hide field from user.
24
+ disabled: Blocks access and modification of the element.
25
+ ignored: If true, the value of this field is not saved in the database.
26
+ hint: An alternative for the `placeholder` parameter.
27
+ warning: Warning information.
28
+ readonly: Specifies that the field cannot be modified by the user.
29
+ slug_sources: List of sources fields.
19
30
  """
20
31
 
21
32
  def __init__( # noqa: D107
22
33
  self,
23
34
  label: str = "",
24
- disabled: bool = False,
35
+ placeholder: str = "",
25
36
  hide: bool = False,
37
+ disabled: bool = False,
26
38
  ignored: bool = False,
27
39
  hint: str = "",
28
40
  warning: list[str] | None = None,
29
- placeholder: str = "",
30
41
  readonly: bool = False,
31
- slug_sources: list[str] = ["_id"],
42
+ slug_sources: list[str] = ["_id"], # noqa: B006
32
43
  ) -> None:
33
44
  if constants.DEBUG:
34
45
  try:
@@ -12,19 +12,36 @@ logger = logging.getLogger(__name__)
12
12
 
13
13
 
14
14
  class TextField(Field, JsonMixin):
15
- """Field of Model for enter text."""
15
+ """Field of Model for enter text.
16
+
17
+ Agrs:
18
+ label: Text label for a web form field.
19
+ placeholder: Displays prompt text.
20
+ hide: Hide field from user.
21
+ disabled: Blocks access and modification of the element.
22
+ ignored: If true, the value of this field is not saved in the database.
23
+ hint: An alternative for the `placeholder` parameter.
24
+ warning: Warning information.
25
+ textarea: Is it necessary to use the Textarea widget.
26
+ use_editor: Is it necessary to use the widget of the text editor.
27
+ required: Required field.
28
+ readonly: Specifies that the field cannot be modified by the user.
29
+ unique: The unique value of a field in a collection.
30
+ maxlength: The maximum line length.
31
+ multi_language: Is it need support for several languages.
32
+ """
16
33
 
17
34
  def __init__( # noqa: D107
18
35
  self,
19
36
  label: str = "",
20
- disabled: bool = False,
37
+ placeholder: str = "",
21
38
  hide: bool = False,
39
+ disabled: bool = False,
22
40
  ignored: bool = False,
23
41
  hint: str = "",
24
42
  warning: list[str] | None = None,
25
43
  textarea: bool = False,
26
44
  use_editor: bool = False,
27
- placeholder: str = "",
28
45
  required: bool = False,
29
46
  readonly: bool = False,
30
47
  unique: bool = False,
@@ -16,30 +16,30 @@ logger = logging.getLogger(__name__)
16
16
  class URLField(Field, TextGroup, JsonMixin):
17
17
  """Field of Model for enter URL address.
18
18
 
19
- Attributes:
20
- label -- Text label for a web form field.
21
- disabled -- Blocks access and modification of the element.
22
- hide -- Hide field from user.
23
- ignored -- If true, the value of this field is not saved in the database.
24
- hint -- An alternative for the `placeholder` parameter.
25
- warning -- Warning information.
26
- default -- Value by default.
27
- placeholder -- Displays prompt text.
28
- required -- Required field.
29
- readonly -- Specifies that the field cannot be modified by the user.
30
- unique -- The unique value of a field in a collection.
19
+ Agrs:
20
+ label: Text label for a web form field.
21
+ placeholder: Displays prompt text.
22
+ default: Value by default.
23
+ hide: Hide field from user.
24
+ disabled: Blocks access and modification of the element.
25
+ ignored: If true, the value of this field is not saved in the database.
26
+ hint: An alternative for the `placeholder` parameter.
27
+ warning: Warning information.
28
+ required: Required field.
29
+ readonly: Specifies that the field cannot be modified by the user.
30
+ unique: The unique value of a field in a collection.
31
31
  """
32
32
 
33
33
  def __init__( # noqa: D107
34
34
  self,
35
35
  label: str = "",
36
- disabled: bool = False,
36
+ placeholder: str = "",
37
+ default: str | None = None,
37
38
  hide: bool = False,
39
+ disabled: bool = False,
38
40
  ignored: bool = False,
39
41
  hint: str = "",
40
42
  warning: list[str] | None = None,
41
- default: str | None = None,
42
- placeholder: str = "",
43
43
  required: bool = False,
44
44
  readonly: bool = False,
45
45
  unique: bool = False,
@@ -1 +1,7 @@
1
- """Models."""
1
+ """Models.
2
+
3
+ This module provides:
4
+
5
+ - `Model`: Converting Python classes into Ramifice Models.
6
+ - `model`: Decorator for converting Python classes into Ramifice models.
7
+ """
@@ -61,13 +61,13 @@ def model(
61
61
  if not exists(fixture_path):
62
62
  msg = (
63
63
  f"Model: `{cls.__module__}.{cls.__name__}` > "
64
- + f"META param: `fixture_name` => "
64
+ + "META param: `fixture_name` => "
65
65
  + f"Fixture the `{fixture_path}` not exists!"
66
66
  )
67
67
  logger.critical(msg)
68
68
  raise PanicError(msg)
69
69
 
70
- attrs = {key: val for key, val in cls.__dict__.items()}
70
+ attrs = dict(cls.__dict__)
71
71
  attrs["__dict__"] = Model.__dict__["__dict__"]
72
72
  metadata = {
73
73
  "service_name": service_name,
ramifice/models/model.py CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  __all__ = ("Model",)
4
4
 
5
- from abc import ABCMeta, abstractmethod
6
- from typing import Any
5
+ from abc import abstractmethod
6
+ from typing import Any, ClassVar
7
7
 
8
8
  import orjson
9
9
  from babel.dates import format_date, format_datetime
@@ -15,10 +15,10 @@ from ramifice.fields import DateTimeField, IDField
15
15
  from ramifice.utils import translations
16
16
 
17
17
 
18
- class Model(metaclass=ABCMeta):
18
+ class Model:
19
19
  """Converting Python Class into Ramifice Model."""
20
20
 
21
- META: dict[str, Any] = {}
21
+ META: ClassVar[dict[str, Any]] = {}
22
22
 
23
23
  def __init__(self) -> None: # noqa: D107
24
24
  _ = translations._
@@ -81,9 +81,7 @@ class Model(metaclass=ABCMeta):
81
81
  if "Dyn" in f_type.field_type:
82
82
  dyn_data = data_dynamic_fields[f_name]
83
83
  if dyn_data is not None:
84
- f_type.choices = [
85
- [item["value"], item["title"][lang]] for item in dyn_data
86
- ]
84
+ f_type.choices = [[item["value"], item["title"][lang]] for item in dyn_data]
87
85
  else:
88
86
  # This is necessary for
89
87
  # `paladins > refrash > RefrashMixin > refrash_from_db`.
@@ -1,4 +1,19 @@
1
- """Paladins - Model instance methods."""
1
+ """Paladins - Model instance methods.
2
+
3
+ This module provides:
4
+
5
+ - `add_validation`: Contains an abstract method for additional validation of fields.
6
+ - `check`: Validation of Model data before saving to the database.
7
+ - `delete`: Delete document from database.
8
+ - `Hooks`: A set of abstract methods for creating hooks.
9
+ - `indexing`: Contains the method for indexing the model in the database.
10
+ - `password`: Verification, replacement and recoverang of password.
11
+ - `refrash_from_db`: Update Model instance from database.
12
+ - `save`: Create or update document in database.
13
+ - `Tools`: A set of auxiliary methods.
14
+ - `is_valid`: Validation of Model.
15
+ - `print_err`: Printing errors to console.
16
+ """
2
17
 
3
18
  __all__ = ("QPaladinsMixin",)
4
19
 
@@ -2,14 +2,15 @@
2
2
 
3
3
  __all__ = ("AddValidMixin",)
4
4
 
5
- from abc import ABCMeta
5
+ from abc import abstractmethod
6
6
 
7
7
  from xloft import NamedTuple
8
8
 
9
9
 
10
- class AddValidMixin(metaclass=ABCMeta):
10
+ class AddValidMixin:
11
11
  """Contains an abstract method for additional validation of fields."""
12
12
 
13
+ @abstractmethod
13
14
  async def add_validation(self) -> NamedTuple:
14
15
  """Additional validation of fields."""
15
16
  return NamedTuple()