| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- from .model import model
- from .proxy import proxy
- from .field_generator import field_generator
- from .constants import constants
- from .validators import validators
- class author(model):
- """
- This model store author or manufacturer who create item. It has name
- and surname, because items created by person exists more than created
- by companies. Name and surname fields would be displayed different way
- when is_person is set to False.
- Fields
- ------
- name : str
- Name of the person, or name of the company.
-
- surname : str
- Surname of the person, or second part of the name of the company.
- description : str
- Description of the author or company.
- is_person : bool
- Binary flag, which is True when author is the person, or False
- when author is the company.
- is_company : bool
- Binary flag, which is True when author is the company, or False
- when author is the person.
- Methods
- -------
- _validators() : dict
- Return dict of validator for text fields.
- """
- name = field_generator.name()
- surname = field_generator.surname()
- description = field_generator.description()
- is_person = field_generator.boolean()
- @property
- def is_company(self) -> bool:
- """ Reverse flag for is_person. """
-
- return not self.is_person
-
- def _validators(self) -> dict:
- """
- It return dict of validators for text fields.
- Returns
- -------
- dict
- Validators for text fields.
- """
- return {
- "name": validators.name,
- "surname": validators.surname,
- "description": validators.description
- }
- class author_proxy(proxy):
- """
- This class is proxy for author. It could be used to make work with
- author objects easier and cleaner.
- Methods
- -------
- @classmethod create : proxy
- That method is used to creating new objects.
- set_name : None
- That set new name and surname of the author.
- set_description : None
- That set new description of the author.
- """
- @classmethod
- def create(cls, name: str, surname: str) -> proxy:
- """
- That create new instance of author with given name and surnme, other
- fields is set to defaults, that mean description is empty, and author
- is the person, not a company.
- Parameters
- ----------
- name : str
- Name of the author.
- surname : str
- Surname of the author.
- Returns
- -------
- proxy
- New proxy with new instance of author inside it.
- """
- return cls(author(
- name = name,
- surname = surname,
- is_person = True,
- description = contants.empty_text()
- ))
- def set_name(self, name: str, surname: str) -> None:
- """
- It set new name and surname of the author.
- Parameters
- ----------
- name : str
- New name of the author.
- surname : str
- Surname of the author.
- """
- self._target.name = name
- self._target.surname = surname
- def set_description(self, target: str) -> None:
- """
- It set new description of the author.
- Parameters
- ----------
- target : str
- Description of the author.
- """
- self._target.description = target
- def make_person(self) -> None:
- """
- It make author the person.
- """
- self._target.is_person = True
- def make_company(self) -> None:
- """
- It make author the company.
- """
- self._target.is_person = False
|