Commit 60ab1e1c authored by Luciano Cauzzi's avatar Luciano Cauzzi

Added Generic Model for managing attachments

parent 458f72bf
from .container import NetworkManager
from .container import PyramidManager
from .pyramid_model import *
......@@ -2,7 +2,7 @@ import json
from typing import Optional
from logger_library import Logger
from network_manager.pyramid_model import AppToken, app_token_from_dict
from network_manager.pyramid_model import AppToken, app_token_from_dict, PyramidDocument
logger = Logger.app_logger().get_logger()
......@@ -38,7 +38,7 @@ class AppPyramidManager:
logger.error("Error while authenticating into pyramid {} \n".format(e))
return None
def save(self, doc) -> bool:
def save(self, doc: PyramidDocument) -> bool:
"""
Saves a document inside pyramid
:param doc:
......@@ -83,7 +83,7 @@ class AppPyramidManager:
logger.exception(e)
return None
def update(self, elastic_id: str, doc) -> bool:
def update(self, elastic_id: str, doc: PyramidDocument) -> bool:
try:
url = "{}/{}/{}".format(self.__base_url__, self.__res_url__, elastic_id)
......
......@@ -46,5 +46,52 @@ class AppToken:
return result
@dataclass
class File:
name: str
content: str
@staticmethod
def from_dict(obj: Any) -> 'File':
assert isinstance(obj, dict)
name = from_str(obj.get("_name"))
content = from_str(obj.get("_content") if obj.get("_content") is not None else "")
return File(name=name, content=content)
def to_dict(self) -> dict:
result: dict = {"_name": from_str(self.name), "_content": from_str(self.content)}
return result
@dataclass
class Attachment:
file: File
@staticmethod
def from_dict(obj: Any) -> 'Attachment':
assert isinstance(obj, dict)
file = File.from_dict(obj.get("file"))
return Attachment(file)
def to_dict(self) -> dict:
result: dict = {"file": to_class(File, self.file)}
return result
@dataclass
class PyramidDocument:
attachments: [Attachment]
@staticmethod
def from_dict(obj: Any) -> 'PyramidDocument':
assert isinstance(obj, dict)
# TODO: missing Attachment
return PyramidDocument([])
def to_dict(self) -> dict:
result: dict = {"attachments": from_list(lambda x: to_class(Attachment, x), self.attachments)}
return result
def app_token_from_dict(s: Any) -> AppToken:
return AppToken.from_dict(s)
......@@ -3,7 +3,7 @@ import setuptools
setup(
name='network_manager',
version='0.1.1',
version='0.1.2',
packages=setuptools.find_packages(),
dependency_links=['http://github.comune.brescia.it/innovation-that-excites/logger_library#egg=logger_library'],
install_requires=['logger_library', 'dependency_injector', 'requests'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment