ModelPropusk.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: str
  29. document: str
  30. class PropuskDataMethods:
  31. def __init__(self, id_propusk: int = None,
  32. date_from: datetime = None,
  33. date_to: datetime = None,
  34. personal: Personal = None,
  35. place: Place = None,
  36. receiving_man: str = None,
  37. purpose_visite: str = None,
  38. face: str = None,
  39. document: str = None):
  40. self._propusk_data = PropuskData(id_propusk,
  41. date_from,
  42. date_to,
  43. personal,
  44. place,
  45. receiving_man,
  46. purpose_visite,
  47. face,
  48. document)
  49. @key_error
  50. def set_value(self, key: str, value: str | int | datetime | Personal | Place):
  51. #Пустышка если ключа не существует выкенет из функции
  52. self._propusk_data.__dict__[key]
  53. self._propusk_data.__dict__[key] = value
  54. @key_error
  55. def get_value(self, key):
  56. return self._propusk_data.__dict__[key]
  57. def checking_empty_values(self) -> bool:
  58. return all(self._propusk_data.__dict__.values())