ramifice 0.4.3__py3-none-any.whl → 0.4.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ramifice/commons/tools.py CHANGED
@@ -23,13 +23,12 @@ def from_mongo_doc(
23
23
  mongo_doc: dict[str, Any],
24
24
  ) -> Any:
25
25
  """Create object instance from Mongo document."""
26
- obj = cls_model()
26
+ obj: Any = cls_model()
27
+ lang: str = translations.CURRENT_LOCALE
27
28
  for name, data in mongo_doc.items():
28
29
  field = obj.__dict__[name]
29
- if "TextField" == field.field_type:
30
- field.value = (
31
- data[translations.CURRENT_LOCALE] if isinstance(field.value, dict) else None
32
- )
30
+ if field.field_type == "TextField":
31
+ field.value = data.get(lang, "") if data is not None else None
33
32
  elif field.group == "pass":
34
33
  field.value = None
35
34
  else:
@@ -50,28 +49,28 @@ def mongo_doc_to_raw_doc(
50
49
  datetime to str
51
50
  """
52
51
  doc: dict[str, Any] = {}
53
- current_locale = translations.CURRENT_LOCALE
52
+ lang: str = translations.CURRENT_LOCALE
54
53
  for f_name, t_name in field_name_and_type.items():
55
54
  value = mongo_doc[f_name]
56
55
  if value is not None:
57
- if "TextField" == t_name:
58
- value = value[current_locale] if isinstance(value, dict) else None
56
+ if t_name == "TextField":
57
+ value = value.get(lang, "") if value is not None else None
59
58
  elif "Date" in t_name:
60
59
  if "Time" in t_name:
61
60
  value = format_datetime(
62
61
  datetime=value,
63
62
  format="short",
64
- locale=current_locale,
63
+ locale=lang,
65
64
  )
66
65
  else:
67
66
  value = format_date(
68
67
  date=value.date(),
69
68
  format="short",
70
- locale=current_locale,
69
+ locale=lang,
71
70
  )
72
- elif "IDField" == t_name:
71
+ elif t_name == "IDField":
73
72
  value = str(value)
74
- elif "PasswordField" == t_name:
73
+ elif t_name == "PasswordField":
75
74
  value = None
76
75
  doc[f_name] = value
77
76
  return doc
@@ -87,11 +87,17 @@ class TextGroupMixin:
87
87
  if params["is_save"]:
88
88
  if is_text_field:
89
89
  mult_lang_text: dict[str, str] = (
90
- params["curr_doc"][field_name] if params["is_update"] else {}
90
+ params["curr_doc"][field_name]
91
+ if params["is_update"]
92
+ else (
93
+ {lang: value for lang in translations.LANGUAGES}
94
+ if isinstance(value, str)
95
+ else {lang: value.get(lang, "") for lang in translations.LANGUAGES}
96
+ )
91
97
  )
92
98
  if isinstance(value, dict):
93
- for lang, text in value.items():
94
- mult_lang_text[lang] = text
99
+ for lang in translations.LANGUAGES:
100
+ mult_lang_text[lang] = value.get(lang, "")
95
101
  else:
96
102
  mult_lang_text[translations.CURRENT_LOCALE] = value
97
103
  value = mult_lang_text
@@ -8,18 +8,17 @@ from ..utils import errors, translations
8
8
  def ignored_fields_to_none(inst_model: Any) -> None:
9
9
  """Reset the values of ignored fields to None."""
10
10
  for _, field_data in inst_model.__dict__.items():
11
- if not callable(field_data) and field_data.ignored and field_data.name != "_id":
11
+ if not callable(field_data) and field_data.ignored:
12
12
  field_data.value = None
13
13
 
14
14
 
15
15
  def refresh_from_mongo_doc(inst_model: Any, mongo_doc: dict[str, Any]) -> None:
16
16
  """Update object instance from Mongo document."""
17
+ lang: str = translations.CURRENT_LOCALE
17
18
  for name, data in mongo_doc.items():
18
19
  field = inst_model.__dict__[name]
19
- if "TextField" == field.field_type:
20
- field.value = (
21
- data[translations.CURRENT_LOCALE] if isinstance(field.value, dict) else None
22
- )
20
+ if field.field_type == "TextField":
21
+ field.value = data.get(lang, "") if data is not None else None
23
22
  elif field.group == "pass":
24
23
  field.value = None
25
24
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ramifice
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: ORM-like API MongoDB for Python language.
5
5
  Project-URL: Homepage, https://github.com/kebasyaty/ramifice
6
6
  Project-URL: Documentation, https://kebasyaty.github.io/ramifice/
@@ -136,6 +136,7 @@ from datetime import datetime
136
136
  from pymongo import AsyncMongoClient
137
137
  from ramifice import model, translations, migration
138
138
  from ramifice.fields import (
139
+ BooleanField,
139
140
  DateField,
140
141
  EmailField,
141
142
  FileField,
@@ -193,13 +194,16 @@ class User:
193
194
  # If true, the value of this field is not saved in the database.
194
195
  ignored=True,
195
196
  )
197
+ self.is_admin = BooleanField(
198
+ label=gettext("Is Administrator?"),
199
+ )
196
200
 
197
201
  # Optional method.
198
202
  async def add_validation(self) -> dict[str, str]:
199
203
  """Additional validation of fields."""
200
204
  gettext = translations.gettext
201
205
  error_map: dict[str, str] = {}
202
- if self.password != self.сonfirm_password:
206
+ if self.password.value != self.сonfirm_password.value:
203
207
  error_map["password"] = gettext("Passwords do not match!")
204
208
  return error_map
205
209
 
@@ -226,6 +230,7 @@ async def main():
226
230
  user.birthday.value = datetime(2000, 1, 25)
227
231
  user.password.value = "12345678"
228
232
  user.сonfirm_password.value = "12345678"
233
+ user.is_admin.value = True
229
234
 
230
235
  # Create User.
231
236
  if not await user.save():
@@ -238,8 +243,14 @@ async def main():
238
243
  user.print_err()
239
244
 
240
245
  print("User details:")
241
- user_details = await User.find_one_to_raw_doc({"_id": user.id.value})
242
- pprint.pprint(user_details)
246
+ user_details = await User.find_one_to_raw_doc(
247
+ # {"_id": user.id.value}
248
+ {f"username.{translations.CURRENT_LOCALE}": user.username.value}
249
+ )
250
+ if user_details is not None:
251
+ pprint.pprint(user_details)
252
+ else:
253
+ print("No User!")
243
254
 
244
255
  # Remove User.
245
256
  await user.delete(remove_files=False)
@@ -5,7 +5,7 @@ ramifice/commons/general.py,sha256=dy2GTpekLyshrNG68XV2dxNgwsS4QODtIcG-c6Xvalw,4
5
5
  ramifice/commons/indexes.py,sha256=hAcWKZ9MMgLbRtoQ6Af0b8r-PY0dbEYmMBl8z_d1DRo,3646
6
6
  ramifice/commons/many.py,sha256=KGt7licVJmLADvyPtH7-GbXHig-EnGFbnk7QKu3mfvQ,8214
7
7
  ramifice/commons/one.py,sha256=h9R-Ev-7h-xln4lp4SMJIIU9Cf9acqwjj4YYaML6uFg,5832
8
- ramifice/commons/tools.py,sha256=ND1s-wt2wf8KhriUrLdCAQ56e7GlxrFZ69GWSwgoocA,2386
8
+ ramifice/commons/tools.py,sha256=zR-mmqqsfSWKF0lws1qMvCh-sauJa8pHX5GNJZdAjMI,2341
9
9
  ramifice/commons/unit_manager.py,sha256=IkWqXu1PHHal0aGfx6zme81iXPeygxPqEWO-u_8RXoI,4356
10
10
  ramifice/fields/__init__.py,sha256=yRfX7Tvpuh27Ggcx5u9e1RRYK7Wu59EVJYxxetmuP1w,1290
11
11
  ramifice/fields/bool_field.py,sha256=WWubSwsFJZu8b3MviDd2zXnNYOQaYw8toklFNSTVFLA,2072
@@ -53,7 +53,7 @@ ramifice/paladins/delete.py,sha256=tw50E98D5eFZ7gHGnh_8ztUB1LeTeWWKZvIcQqlgbF8,3
53
53
  ramifice/paladins/password.py,sha256=w1XWh3bsncH1VTVjCLxyKI2waxMvltwcsPWW3V9Ib84,3027
54
54
  ramifice/paladins/refrash.py,sha256=fw-9x_NKGzreipBt_F9KF6FTsYm9hSzfq4ubi1FHYrQ,1065
55
55
  ramifice/paladins/save.py,sha256=EG0_v-imCQPax2pJIAXPoQcSL99g8abY2EeGJMvXBW4,3864
56
- ramifice/paladins/tools.py,sha256=SCmESo8isvcy0yk43Rj1J5BZ1xSZbNV1KLhhBrzfezY,2687
56
+ ramifice/paladins/tools.py,sha256=QxxwZILyBLcAiDUN48KE99c_cHVjG-VYilEsIinRhEU,2641
57
57
  ramifice/paladins/validation.py,sha256=gcEJXIEPu1g7Z54vl14YTs5rCmxOEYsgQH1usFfyy7k,1730
58
58
  ramifice/paladins/groups/__init__.py,sha256=hpqmWLsYAMvZHAbmMXluQSqLhkHOSTUAgLHyTM1LTYI,472
59
59
  ramifice/paladins/groups/bool_group.py,sha256=oJc9mw9KGrnK_Pj7uXixYYQAJphcXLr_xSQv3PMUlcU,792
@@ -65,7 +65,7 @@ ramifice/paladins/groups/img_group.py,sha256=RoD_QnW0F0DAzrGQmRi8jMZnWy2IomlFn6A
65
65
  ramifice/paladins/groups/num_group.py,sha256=6jT7nfIiVoQTlI2UdkcQOlHIDYjllFqSH7Nb87uJgzg,2274
66
66
  ramifice/paladins/groups/pass_group.py,sha256=YU5a-NwohEutoEx2N5JmGfg8uPiYiW0XJ8XYsOih6eA,1859
67
67
  ramifice/paladins/groups/slug_group.py,sha256=joBB5litljbv2h5JKEMzF71s_DKMWH6nzgThLiLZx2E,2307
68
- ramifice/paladins/groups/text_group.py,sha256=67gk-vEoZImifCqIzWYexc0Yj2__srFAUqmOHRhBgOk,4005
68
+ ramifice/paladins/groups/text_group.py,sha256=rUWNaAPkTMMlRf6A-6nQAa4HCj6NBTjPKIYaEKSOUL4,4305
69
69
  ramifice/utils/__init__.py,sha256=xixHoOX4ja5jIUZemem1qn4k4aonv3G3Q76azQK_pkU,43
70
70
  ramifice/utils/errors.py,sha256=iuhq7fzpUmsOyeXeg2fJjta8yAuqlXLKsZVMpfUhtHE,1901
71
71
  ramifice/utils/fixtures.py,sha256=Krl31nNShEg6A15Q8WRDqIai0bPyaJuK8jEGt5ySzao,3114
@@ -79,7 +79,7 @@ ramifice/utils/mixins/add_valid.py,sha256=TLOObedzXNA9eCylfAVbVCqIKE5sV-P5AdIN7a
79
79
  ramifice/utils/mixins/hooks.py,sha256=33jvJRhfnJeL2Hd_YFXk3M_7wjqHaByU2wRjKyboL6s,914
80
80
  ramifice/utils/mixins/indexing.py,sha256=Z0427HoaVRyNmSNN8Fx0mSICgAKV-gDdu3iR5qYUEbs,329
81
81
  ramifice/utils/mixins/json_converter.py,sha256=WhigXyDAV-FfILaZuwvRFRIk0D90Rv3dG5t-mv5fVyc,1107
82
- ramifice-0.4.3.dist-info/METADATA,sha256=JSgLC_LmwUU-SwrQp7uEF5lQDn9xsAAUe_F08XHY1d0,21049
83
- ramifice-0.4.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
84
- ramifice-0.4.3.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
85
- ramifice-0.4.3.dist-info/RECORD,,
82
+ ramifice-0.4.5.dist-info/METADATA,sha256=2gwEZsJJmFhhFAayDTWsB1kIKwWNmeadZVMt-4Fgwyc,21369
83
+ ramifice-0.4.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
84
+ ramifice-0.4.5.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
85
+ ramifice-0.4.5.dist-info/RECORD,,