This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/resources/tradedocument/schemas.py

31 lines
1.2 KiB
Python
Raw Normal View History

2021-05-19 07:47:14 +00:00
import base64
from marshmallow.fields import DateTime, Integer, Raw
2021-05-13 11:35:46 +00:00
from teal.marshmallow import SanitizedStr
2021-05-19 07:47:14 +00:00
from marshmallow import ValidationError, validates_schema
2021-05-13 11:35:46 +00:00
2021-05-19 07:47:14 +00:00
from ereuse_devicehub.marshmallow import NestedOn
2021-05-13 11:35:46 +00:00
from ereuse_devicehub.resources.schemas import Thing
from ereuse_devicehub.resources.tradedocument import models as m
2021-05-19 07:47:14 +00:00
from ereuse_devicehub.resources.lot import schemas as s_lot
2021-05-13 11:35:46 +00:00
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)
2021-05-19 07:47:14 +00:00
file = Raw(type='file')
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'])