ModelPropusk.py 1.8 KB

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