attachment.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from .model import model
  2. from .proxy import proxy
  3. from .field_generator import field_generator
  4. from .constants import constants
  5. from .validators import validators
  6. class attachment(model):
  7. """
  8. That model store attachment to the item. Attachment is file, which could
  9. be downloaded by the user, like instruction in PDF, or used in frontend
  10. like images.
  11. Fields
  12. ------
  13. name : str
  14. Name of the attachment visible for user.
  15. description : str
  16. Description of the attachment visible for user.
  17. """
  18. name = field_generator.name()
  19. description = field_generator.description()
  20. def _validators(self) -> dict:
  21. """
  22. That function return dict of validators which would be used to
  23. validate text fields of the model.
  24. Returns
  25. -------
  26. dict
  27. Validators which would be used to validate text fields.
  28. """
  29. return {
  30. "name": validators.name,
  31. "description": validators.description
  32. }
  33. class attachment_proxy(proxy):
  34. """
  35. That class is proxy for the attachment. It could be used to working
  36. witch attachments in cleaner and better way.
  37. Methods
  38. -------
  39. @classmethod create : proxy
  40. That create new attachment from that name.
  41. """
  42. @classmethod
  43. def create(cls, name: str) -> proxy:
  44. return cls(attachment(
  45. name = name,
  46. description = constants.empty_text()
  47. ))
  48. def set_name(self, target: str) -> None:
  49. self._target.name = target
  50. def set_description(self, target: str) -> None:
  51. self._target.description = target