ModelPropusk.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from datetime import datetime
  2. from dataclasses import dataclass
  3. from logger import logger
  4. def key_error(func):
  5. def wrapper(*args, **kwargs):
  6. try:
  7. return func(*args, **kwargs)
  8. except KeyError:
  9. logger.info("ModelPropusk -> Ключ не правильный")
  10. return wrapper
  11. @dataclass
  12. class Personal:
  13. id: int
  14. name: str
  15. @dataclass
  16. class Place:
  17. id: int
  18. name: str
  19. @dataclass
  20. class PropuskData:
  21. id_propusk: int
  22. date_from: datetime
  23. date_to: datetime
  24. personal: Personal
  25. place: Place
  26. receiving_man: str
  27. purpose_visite: str
  28. face_photo: str
  29. class PropuskDataMethods:
  30. def __init__(self, id_propusk: int = None,
  31. date_from: datetime = None,
  32. date_to: datetime = None,
  33. personal: Personal = None,
  34. place: Place = None,
  35. receiving_man: str = None,
  36. purpose_visite: str = None,
  37. face_photo: str = None):
  38. self._propusk_data = PropuskData(id_propusk,
  39. date_from,
  40. date_to,
  41. personal,
  42. place,
  43. receiving_man,
  44. purpose_visite,
  45. face_photo)
  46. @key_error
  47. def set_value(self, key: str, value: str | int | datetime | Personal | Place):
  48. #Пустышка если ключа не существует выкенет из функции
  49. self._propusk_data.__dict__[key]
  50. self._propusk_data.__dict__[key] = value
  51. @key_error
  52. def get_value(self, key):
  53. return self._propusk_data.__dict__[key]
  54. def checking_empty_values(self) -> bool:
  55. return all(self._propusk_data.__dict__.values())