|
|
@@ -5,12 +5,58 @@ from .constants import constants
|
|
|
from .validators import validators
|
|
|
|
|
|
class author(model):
|
|
|
- id = field_generator.id()
|
|
|
+ """
|
|
|
+ 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,
|
|
|
@@ -18,18 +64,89 @@ class author(model):
|
|
|
}
|
|
|
|
|
|
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
|
|
|
+
|