sysnet-pyutils 1.2.4__py3-none-any.whl → 1.2.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.
@@ -5,6 +5,8 @@ import pytz
5
5
 
6
6
  from sysnet_pyutils.utils import is_valid_email, TZ
7
7
 
8
+ PAGE_SIZE = 10
9
+
8
10
  def get_dict_value(data: dict, item_name: str) -> Union[Any, None]:
9
11
  """
10
12
  Extrahuje hodnotu ze slovníku. Používá se pro load dat JSON do objektů
@@ -320,3 +322,52 @@ def dict_convert_date_to_str(data: dict):
320
322
  dict_convert_date_to_str(item)
321
323
  else:
322
324
  pass
325
+
326
+
327
+ def paging_to_mongo(start=0, page_size=PAGE_SIZE, page=0):
328
+ if start is None:
329
+ start = 0
330
+ if page_size is None:
331
+ page_size = PAGE_SIZE
332
+ if page is None:
333
+ page = 0
334
+ page += start // page_size
335
+ start = start % page_size
336
+ # pokud pocatecni dokument nesouhlasí se začátkem stránky, zkrátí se stránka
337
+ skip = start + page * page_size
338
+ limit = page_size
339
+ if start != 0:
340
+ limit = page_size - start
341
+ out = {
342
+ 'start': start,
343
+ 'page_size': page_size,
344
+ 'page': page,
345
+ 'skip': skip,
346
+ 'limit': limit}
347
+ return out
348
+
349
+
350
+ def recursive_update(out_object, original, updated):
351
+ """
352
+ Rekurzivní aktualizace slovníků
353
+
354
+ :param out_object: Datový objekt k aktualizaci
355
+ :param original: Uložený slovník
356
+ :param updated: Aktualizace (dodaná metodou PUT)
357
+ :return: Aktualizovaný původní slovník
358
+ """
359
+ out = original
360
+ for k, v in updated.items():
361
+ if k not in out:
362
+ # Ignoruj položky, které nejsou v originále
363
+ continue
364
+ if (v is None) and (isinstance(out.get(k), dict) or isinstance(out.get(k), list)):
365
+ # Pokud je místo slovníku nebo seznamu None, přeskočit
366
+ continue
367
+ if isinstance(v, dict) and isinstance(out.get(k), dict):
368
+ # Pokud je aktualizován slovník, rekurze
369
+ recursive_update(getattr(out_object, k), out[k], v)
370
+ else:
371
+ out[k] = v
372
+ setattr(out_object, k, v)
373
+ return out
@@ -1,11 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import json
4
+ import pprint
4
5
  from datetime import datetime
5
6
  from enum import Enum
6
- from typing import Optional, List, Tuple, Any
7
+ from typing import Optional, List, Tuple, Any, ClassVar, Dict
7
8
 
8
- from pydantic import BaseModel, Field, EmailStr
9
+ from pydantic import BaseModel, Field, EmailStr, StrictStr, StrictBool
9
10
  from typing_extensions import Self
10
11
 
11
12
  from sysnet_pyutils.utils import local_now, is_valid_unid, is_valid_pid, is_valid_uuid
@@ -74,7 +75,13 @@ class AclLevelEnum(BaseEnum):
74
75
 
75
76
  class PersonTypeEnum(BaseEnum):
76
77
  """
77
- Typ osoby (zdroj CRŽP): - legalEntity: tuzemská právnická osoba - legalEntityWithoutIco: tuzemská právnická osoba bez IČO - foreignLegalEntity: zahraniční právnická osoba - businessNaturalPerson: tuzemská fyzická osoba podnikající - naturalPerson: tuzemská fyzická osoba nepodnikající - foreignNaturalPerson: zahraniční fyzická osoba podnikající
78
+ Typ osoby (zdroj CRŽP):
79
+ - legalEntity: tuzemská právnická osoba
80
+ - legalEntityWithoutIco: tuzemská právnická osoba bez IČO
81
+ - foreignLegalEntity: zahraniční právnická osoba
82
+ - businessNaturalPerson: tuzemská fyzická osoba podnikající
83
+ - naturalPerson: tuzemská fyzická osoba nepodnikající
84
+ - foreignNaturalPerson: zahraniční fyzická osoba podnikající
78
85
  """
79
86
  LEGAL_ENTITY = 'legalEntity'
80
87
  LEGAL_ENTITY_WO_ICO = 'legalEntityWithoutIco'
@@ -143,6 +150,20 @@ class AclType(BaseModel):
143
150
  )
144
151
 
145
152
 
153
+ class MetadataEssentialType(BaseModel):
154
+ """
155
+ Hlavní metadata
156
+ """ # noqa: E501
157
+ identifier: Optional[StrictStr] = Field(default=None, description="identifikátor uuid")
158
+ date_created: Optional[datetime] = Field(default=None, description="Datum a čas")
159
+ date_modified: Optional[datetime] = Field(default=None, description="Datum a čas")
160
+ date_deleted: Optional[datetime] = Field(default=None, description="Datum a čas")
161
+ deleted: Optional[StrictBool] = Field(default=False, description="Dokument byl odstraněn")
162
+ valid: Optional[StrictBool] = Field(default=True, description="Dokument je platný/neplatný")
163
+ duplicates: Optional[StrictStr] = Field(default=None, description="Dokument je duplicitní k jinému dokumentu s daným identifikátorem")
164
+
165
+
166
+
146
167
  class MetadataTypeEntry(BaseModel):
147
168
  title: Optional[str] = Field(default=None, description='Název dokumentu')
148
169
  id_no: Optional[str] = Field(default=None, description='Číslo dokumentu', examples=['23CZ123456'])
@@ -315,3 +336,155 @@ class WorkflowType(BaseModel):
315
336
  status_to: Optional[str] = Field(default=None, description='Následný stav')
316
337
 
317
338
 
339
+ class PhoneNumberType(BaseModel):
340
+ """
341
+ Telefonní číslo
342
+ """ # noqa: E501
343
+ name: Optional[StrictStr] = Field(default=None, description="Název telefonního čísla (mobil, práce, domů)")
344
+ prefix: Optional[StrictStr] = Field(default=None, description="Národní prefix")
345
+ number: Optional[StrictStr] = Field(default=None, description="Vlastní telefonní číslo")
346
+ __properties: ClassVar[List[str]] = ["name", "prefix", "number"]
347
+
348
+ model_config = {
349
+ "populate_by_name": True,
350
+ "validate_assignment": True,
351
+ "protected_namespaces": (),
352
+ }
353
+
354
+
355
+ def to_str(self) -> str:
356
+ """Returns the string representation of the model using alias"""
357
+ return pprint.pformat(self.model_dump(by_alias=True))
358
+
359
+ def to_json(self) -> str:
360
+ """Returns the JSON representation of the model using alias"""
361
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
362
+ return json.dumps(self.to_dict())
363
+
364
+ @classmethod
365
+ def from_json(cls, json_str: str) -> Self:
366
+ """Create an instance of PhoneNumberType from a JSON string"""
367
+ return cls.from_dict(json.loads(json_str))
368
+
369
+ def to_dict(self) -> Dict[str, Any]:
370
+ """Return the dictionary representation of the model using alias.
371
+
372
+ This has the following differences from calling pydantic's
373
+ `self.model_dump(by_alias=True)`:
374
+
375
+ * `None` is only added to the output dict for nullable fields that
376
+ were set at model initialization. Other fields with value `None`
377
+ are ignored.
378
+ """
379
+ _dict = self.model_dump(
380
+ by_alias=True,
381
+ exclude={
382
+ },
383
+ exclude_none=True,
384
+ )
385
+ # set to None if name (nullable) is None
386
+ # and model_fields_set contains the field
387
+ if self.name is None and "name" in self.model_fields_set:
388
+ _dict['name'] = None
389
+
390
+ # set to None if prefix (nullable) is None
391
+ # and model_fields_set contains the field
392
+ if self.prefix is None and "prefix" in self.model_fields_set:
393
+ _dict['prefix'] = None
394
+
395
+ # set to None if number (nullable) is None
396
+ # and model_fields_set contains the field
397
+ if self.number is None and "number" in self.model_fields_set:
398
+ _dict['number'] = None
399
+
400
+ return _dict
401
+
402
+ @classmethod
403
+ def from_dict(cls, obj: Dict) -> Self:
404
+ """Create an instance of PhoneNumberType from a dict"""
405
+ if obj is None:
406
+ return None
407
+
408
+ if not isinstance(obj, dict):
409
+ return cls.model_validate(obj)
410
+
411
+ _obj = cls.model_validate({
412
+ "name": obj.get("name"),
413
+ "prefix": obj.get("prefix"),
414
+ "number": obj.get("number")
415
+ })
416
+ return _obj
417
+
418
+
419
+ class MailAddressType(BaseModel):
420
+ """
421
+ Adresa elektronické pošty
422
+ """ # noqa: E501
423
+ name: Optional[StrictStr] = Field(default=None, description="Název adresa elektronické pošty (práce, domů)")
424
+ email: Optional[StrictStr] = Field(default=None, description="Adresa elektronické pošty")
425
+ __properties: ClassVar[List[str]] = ["name", "email"]
426
+
427
+ model_config = {
428
+ "populate_by_name": True,
429
+ "validate_assignment": True,
430
+ "protected_namespaces": (),
431
+ }
432
+
433
+
434
+ def to_str(self) -> str:
435
+ """Returns the string representation of the model using alias"""
436
+ return pprint.pformat(self.model_dump(by_alias=True))
437
+
438
+ def to_json(self) -> str:
439
+ """Returns the JSON representation of the model using alias"""
440
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
441
+ return json.dumps(self.to_dict())
442
+
443
+ @classmethod
444
+ def from_json(cls, json_str: str) -> Self:
445
+ """Create an instance of MailAddressType from a JSON string"""
446
+ return cls.from_dict(json.loads(json_str))
447
+
448
+ def to_dict(self) -> Dict[str, Any]:
449
+ """Return the dictionary representation of the model using alias.
450
+
451
+ This has the following differences from calling pydantic's
452
+ `self.model_dump(by_alias=True)`:
453
+
454
+ * `None` is only added to the output dict for nullable fields that
455
+ were set at model initialization. Other fields with value `None`
456
+ are ignored.
457
+ """
458
+ _dict = self.model_dump(
459
+ by_alias=True,
460
+ exclude={
461
+ },
462
+ exclude_none=True,
463
+ )
464
+ # set to None if name (nullable) is None
465
+ # and model_fields_set contains the field
466
+ if self.name is None and "name" in self.model_fields_set:
467
+ _dict['name'] = None
468
+
469
+ # set to None if email (nullable) is None
470
+ # and model_fields_set contains the field
471
+ if self.email is None and "email" in self.model_fields_set:
472
+ _dict['email'] = None
473
+
474
+ return _dict
475
+
476
+ @classmethod
477
+ def from_dict(cls, obj: Dict) -> Self:
478
+ """Create an instance of MailAddressType from a dict"""
479
+ if obj is None:
480
+ return None
481
+
482
+ if not isinstance(obj, dict):
483
+ return cls.model_validate(obj)
484
+
485
+ _obj = cls.model_validate({
486
+ "name": obj.get("name"),
487
+ "email": obj.get("email")
488
+ })
489
+ return _obj
490
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sysnet-pyutils
3
- Version: 1.2.4
3
+ Version: 1.2.6
4
4
  Summary: Python Utilities
5
5
  Author-email: Data Developer <info@sysnet.cz>
6
6
  Project-URL: Homepage, https://github.com/SYSNET-CZ/pyutils
@@ -1,6 +1,6 @@
1
1
  sysnet_pyutils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  sysnet_pyutils/barcode.py,sha256=5dM1ISvVVP966JQxGiZBUYJoPx_jgzWEpEQ2uIOxTd4,2622
3
- sysnet_pyutils/data_utils.py,sha256=foePXYsPJyl7zdzb4RENO937uNV5G05GdW_En6ql4kw,9673
3
+ sysnet_pyutils/data_utils.py,sha256=1OV89carnQCQgB7wahTEsfg-jR6bQcsz0-NKiiSlk00,11283
4
4
  sysnet_pyutils/domino.py,sha256=dGmg9d1PMPOyA_ysXBHVu_zabKGCJEuno3Yw3DexExQ,2671
5
5
  sysnet_pyutils/geo.py,sha256=smAkRfobvKqjr3_UIjU5huDbnkb3_edD_xmv4R0r5Q0,2938
6
6
  sysnet_pyutils/ident.py,sha256=OkGne8xLEFd2zNdIm7HTPJ_K-fIN9rz7tOR-H0PWDRE,2845
@@ -9,9 +9,9 @@ sysnet_pyutils/ses.py,sha256=WJzs0y2QnF4XGDGjls_W0p0v6DJ4fZ4_97m3XbzpaFw,2713
9
9
  sysnet_pyutils/tools.py,sha256=ZioHvUIufrhuJyZLdPnuMUD8Li5LTljSMSCxqRnKIi4,377
10
10
  sysnet_pyutils/utils.py,sha256=4dOqlP8JhKaIzWlbYw4PLckBf1SigBJK-MzK1EWTgYk,23523
11
11
  sysnet_pyutils/models/__init__.py,sha256=oozOr_DKhenkM9BDaPOmtbLXhP5vtMUCjBPEjZDW4GQ,167
12
- sysnet_pyutils/models/general.py,sha256=N3meFkl5v3wxEkP9jOy-leOobRhfhKDKgzu2b0BCmrc,17228
13
- sysnet_pyutils-1.2.4.dist-info/licenses/LICENSE,sha256=bx5iLIKjgAdYQ7sISn7DsfHRKkoCUm1154sJJKhgqnU,35184
14
- sysnet_pyutils-1.2.4.dist-info/METADATA,sha256=ZxxTqw45stJQZY4tP1hiB2E5_zDwNHJMkQPvgcX9txM,15747
15
- sysnet_pyutils-1.2.4.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
16
- sysnet_pyutils-1.2.4.dist-info/top_level.txt,sha256=ZKTltQWbLlWBXw4oovo1w7ui-JQ1WoyECqMSWdBj6XE,15
17
- sysnet_pyutils-1.2.4.dist-info/RECORD,,
12
+ sysnet_pyutils/models/general.py,sha256=6AE5RfLmvW4oq7V6Iqpbq7l-Lsqt2Kkh7yLaXu58fRc,23386
13
+ sysnet_pyutils-1.2.6.dist-info/licenses/LICENSE,sha256=bx5iLIKjgAdYQ7sISn7DsfHRKkoCUm1154sJJKhgqnU,35184
14
+ sysnet_pyutils-1.2.6.dist-info/METADATA,sha256=O82RV1UCz3ql195OhtV35UdWlHLDYKXm2bzriw10el0,15747
15
+ sysnet_pyutils-1.2.6.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
16
+ sysnet_pyutils-1.2.6.dist-info/top_level.txt,sha256=ZKTltQWbLlWBXw4oovo1w7ui-JQ1WoyECqMSWdBj6XE,15
17
+ sysnet_pyutils-1.2.6.dist-info/RECORD,,