ramifice 0.4.4__py3-none-any.whl → 0.4.6__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
@@ -14,10 +14,11 @@ def ignored_fields_to_none(inst_model: Any) -> None:
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
20
  if field.field_type == "TextField":
20
- field.value = data[translations.CURRENT_LOCALE] if isinstance(data, dict) else None
21
+ field.value = data.get(lang, "") if data is not None else None
21
22
  elif field.group == "pass":
22
23
  field.value = None
23
24
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ramifice
3
- Version: 0.4.4
3
+ Version: 0.4.6
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/
@@ -203,7 +203,7 @@ class User:
203
203
  """Additional validation of fields."""
204
204
  gettext = translations.gettext
205
205
  error_map: dict[str, str] = {}
206
- if self.password.value != self.сonfirm_password.value:
206
+ if self.id.value is None and (self.password.value != self.сonfirm_password.value):
207
207
  error_map["password"] = gettext("Passwords do not match!")
208
208
  return error_map
209
209
 
@@ -243,12 +243,23 @@ async def main():
243
243
  user.print_err()
244
244
 
245
245
  print("User details:")
246
- user_details = await User.find_one_to_raw_doc({"_id": user.id.value})
247
- pprint.pprint(user_details)
246
+ user_details = await User.find_one_to_raw_doc(
247
+ # {"_id": user.id.value}
248
+ # For `TextField`.
249
+ {f"username.{translations.CURRENT_LOCALE}": user.username.value}
250
+ )
251
+ if user_details is not None:
252
+ pprint.pprint(user_details)
253
+ else:
254
+ print("No User!")
248
255
 
249
256
  # Remove User.
250
257
  await user.delete(remove_files=False)
251
258
 
259
+ # Remove collection.
260
+ # (if necessary)
261
+ await User.collection().drop()
262
+
252
263
  await client.close()
253
264
 
254
265
 
@@ -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=7F66koM5In1skViEWExBbSxuGrKh1k-RqaawuRFuEj4,2617
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
@@ -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.4.dist-info/METADATA,sha256=6oAjlZe-e-NlTj03piyFrubVkp7dvH8uzkHOf1qeUgo,21207
83
- ramifice-0.4.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
84
- ramifice-0.4.4.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
85
- ramifice-0.4.4.dist-info/RECORD,,
82
+ ramifice-0.4.6.dist-info/METADATA,sha256=JzUrCs-zDKXvkX7QfbiIzrhoRB8mK-Nl3rcMAaS_rAY,21506
83
+ ramifice-0.4.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
84
+ ramifice-0.4.6.dist-info/licenses/LICENSE,sha256=LrEL0aTZx90HDwFUQCJutORiDjJL9AnuVvCtspXIqt4,1095
85
+ ramifice-0.4.6.dist-info/RECORD,,