|
|
@@ -5,7 +5,6 @@ from .proxy import proxy
|
|
|
from .field_generator import field_generator
|
|
|
from .constants import constants
|
|
|
from .validators import validators
|
|
|
-from .attachment_file import attachment_file
|
|
|
from .exceptions import resources_not_exists
|
|
|
|
|
|
class attachment(model):
|
|
|
@@ -26,7 +25,10 @@ class attachment(model):
|
|
|
name = field_generator.name()
|
|
|
description = field_generator.description()
|
|
|
resources = field_generator.path()
|
|
|
-
|
|
|
+
|
|
|
+ @property
|
|
|
+ def resources_path(self) -> pathlib.Path:
|
|
|
+ return pathlib.Path(self.resources)
|
|
|
|
|
|
def _validators(self) -> dict:
|
|
|
"""
|
|
|
@@ -46,95 +48,29 @@ class attachment(model):
|
|
|
}
|
|
|
|
|
|
class attachment_proxy(proxy):
|
|
|
- """
|
|
|
- That class is proxy for the attachment. It could be used to working
|
|
|
- witch attachments in cleaner and better way.
|
|
|
-
|
|
|
- Methods
|
|
|
- -------
|
|
|
- @classmethod create : proxy
|
|
|
- That create new attachment from that name.
|
|
|
-
|
|
|
- set_name : None
|
|
|
- That change visible name of the attachment.
|
|
|
-
|
|
|
- set_description : None
|
|
|
- That change description of the attachment.
|
|
|
- """
|
|
|
-
|
|
|
@classmethod
|
|
|
- def create(cls, name: str, resources: attachment_file) -> proxy:
|
|
|
- """
|
|
|
- That create new proxy with new object, which does not exists in
|
|
|
- database inside.
|
|
|
-
|
|
|
- Parameters
|
|
|
- ----------
|
|
|
- name : str
|
|
|
- Name of the new attachment.
|
|
|
- resources : str
|
|
|
- Path in the resources directory to the attachment file.
|
|
|
-
|
|
|
- Raises
|
|
|
- ------
|
|
|
- resources_not_exists
|
|
|
- When attachment file does not exists on disk.
|
|
|
-
|
|
|
- Returns
|
|
|
- -------
|
|
|
- proxy
|
|
|
- New proxy with new attachment inside it.
|
|
|
- """
|
|
|
-
|
|
|
- if not resources.exists():
|
|
|
- raise resources_not_exists(resources.path)
|
|
|
-
|
|
|
+ def create(cls, resources: str) -> proxy:
|
|
|
return cls(attachment(
|
|
|
- name = name,
|
|
|
- description = constants.empty_text(),
|
|
|
- resources = resources.name
|
|
|
+ name = cls.__extract_name(resources),
|
|
|
+ resources = resources,
|
|
|
+ description = constants.empty_text()
|
|
|
))
|
|
|
|
|
|
- def set_resources(self, target: attachment_file) -> None:
|
|
|
- """
|
|
|
- That change path to the attachment file in the resources directory.
|
|
|
-
|
|
|
- Parameters
|
|
|
- ----------
|
|
|
- target : pathlib.Path
|
|
|
- Path to new attachment file in the resources directory.
|
|
|
-
|
|
|
- Raises
|
|
|
- ------
|
|
|
- resources_not_exists
|
|
|
- When attachment file does not exists on disk.
|
|
|
- """
|
|
|
-
|
|
|
- if not target.exists():
|
|
|
- raise resources_not_exists(target.path)
|
|
|
+ @classmethod
|
|
|
+ def __extract_name(cls, resources: str) -> str:
|
|
|
+ splited = resources.split(".")
|
|
|
|
|
|
- self._target.resources = target.name
|
|
|
+ if len(splited) == 1:
|
|
|
+ return splited[0]
|
|
|
|
|
|
- def set_name(self, target: str) -> None:
|
|
|
- """
|
|
|
- That change name of the attachment
|
|
|
-
|
|
|
- Parameters
|
|
|
- ----------
|
|
|
- target : str
|
|
|
- New name of the attachment to set.
|
|
|
- """
|
|
|
+ return str(".").join(splited[:-1])
|
|
|
|
|
|
+ def set_name(self, target: str) -> object:
|
|
|
self._target.name = target
|
|
|
+ return self
|
|
|
|
|
|
- def set_description(self, target: str) -> None:
|
|
|
- """
|
|
|
- That chanhe description of the attachment.
|
|
|
+ def set_description(self, target: str) -> object:
|
|
|
+ self._target.description = target
|
|
|
+ return self
|
|
|
|
|
|
- Parameters
|
|
|
- ----------
|
|
|
- target : str
|
|
|
- New description of the attachment to set.
|
|
|
- """
|
|
|
|
|
|
- self._target.description = target
|