From b1414cf1435417d73ae0ef80e73846aef4b94045 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 15 Jun 2021 12:38:02 +0200 Subject: [PATCH] redefine models --- .../resources/tradedocument/models.py | 6 ++-- .../resources/tradedocument/schemas.py | 33 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/ereuse_devicehub/resources/tradedocument/models.py b/ereuse_devicehub/resources/tradedocument/models.py index 409d34eb..7f15f9b1 100644 --- a/ereuse_devicehub/resources/tradedocument/models.py +++ b/ereuse_devicehub/resources/tradedocument/models.py @@ -77,8 +77,10 @@ class TradeDocument(Thing): lot.comment = """Lot to which the document is associated""" file_name = Column(db.CIText()) file_name.comment = """This is the name of the file when user up the document.""" - path_name = Column(db.CIText()) - path_name.comment = """This is the name of the file as devicehub save in server.""" + file_hash = Column(db.CIText()) + file_hash.comment = """This is the hash of the file produced from frontend.""" + url = Column(db.CIText()) + url.comment = """This is the url where resides the document.""" __table_args__ = ( db.Index('document_id', id, postgresql_using='hash'), diff --git a/ereuse_devicehub/resources/tradedocument/schemas.py b/ereuse_devicehub/resources/tradedocument/schemas.py index e565afc2..e63610ec 100644 --- a/ereuse_devicehub/resources/tradedocument/schemas.py +++ b/ereuse_devicehub/resources/tradedocument/schemas.py @@ -1,8 +1,6 @@ -import base64 - -from marshmallow.fields import DateTime, Integer, Raw -from teal.marshmallow import SanitizedStr -from marshmallow import ValidationError, validates_schema +from marshmallow.fields import DateTime, Integer +from teal.marshmallow import SanitizedStr, URL +# from marshmallow import ValidationError, validates_schema from ereuse_devicehub.marshmallow import NestedOn from ereuse_devicehub.resources.schemas import Thing @@ -14,18 +12,17 @@ class TradeDocument(Thing): __doc__ = m.TradeDocument.__doc__ id = Integer(description=m.TradeDocument.id.comment, dump_only=True) date = DateTime(required=False, description=m.TradeDocument.date.comment) - id_document = SanitizedStr(default='', description=m.TradeDocument.id_document.comment) - description = SanitizedStr(default='', description=m.TradeDocument.description.comment) - file_name = SanitizedStr(default='', description=m.TradeDocument.file_name.comment) - file = Raw(type='file') + id_document = SanitizedStr(data_key='documentId', + default='', + description=m.TradeDocument.id_document.comment) + description = SanitizedStr(default='', + description=m.TradeDocument.description.comment) + file_name = SanitizedStr(data_key='filename', + default='', + description=m.TradeDocument.file_name.comment) + file_hash = SanitizedStr(data_key='hash', + default='', + description=m.TradeDocument.file_hash.comment) + url = URL(description=m.TradeDocument.url.comment) lot = NestedOn('Lot', only_query='id', description=m.TradeDocument.lot.__doc__) # lot = NestedOn(s_lot.Lot, only_query='id', description=m.TradeDocument.lot.__doc__) - - - @validates_schema - def validate_filestream(self, data): - if not data.get('file'): - txt = 'Error, no there are any file for save' - raise ValidationError(txt) - - data['file'] = base64.b64decode(data['file'])