2021-08-10 10:45:03 +00:00
|
|
|
from marshmallow.fields import DateTime, Integer, validate, Boolean, Float
|
|
|
|
from marshmallow import post_load
|
|
|
|
from marshmallow.validate import Range
|
2021-07-21 06:35:18 +00:00
|
|
|
from teal.marshmallow import SanitizedStr, URL
|
2021-08-10 10:45:03 +00:00
|
|
|
from ereuse_devicehub.marshmallow import NestedOn
|
2021-07-21 06:35:18 +00:00
|
|
|
from ereuse_devicehub.resources.schemas import Thing
|
2021-08-10 10:45:03 +00:00
|
|
|
from ereuse_devicehub.resources.tradedocument.models import TradeDocument
|
2021-07-21 06:35:18 +00:00
|
|
|
from ereuse_devicehub.resources.documents import models as m
|
|
|
|
|
|
|
|
|
2021-07-29 13:46:49 +00:00
|
|
|
class DataWipeDocument(Thing):
|
|
|
|
__doc__ = m.DataWipeDocument.__doc__
|
|
|
|
id = Integer(description=m.DataWipeDocument.id.comment, dump_only=True)
|
2021-08-06 09:08:58 +00:00
|
|
|
url = URL(required= False, description=m.DataWipeDocument.url.comment)
|
|
|
|
success = Boolean(required=False, default=False, description=m.DataWipeDocument.success.comment)
|
2021-07-29 13:46:49 +00:00
|
|
|
software = SanitizedStr(description=m.DataWipeDocument.software.comment)
|
2021-07-21 06:35:18 +00:00
|
|
|
date = DateTime(data_key='endTime',
|
|
|
|
required=False,
|
2021-07-29 13:46:49 +00:00
|
|
|
description=m.DataWipeDocument.date.comment)
|
2021-07-21 06:35:18 +00:00
|
|
|
id_document = SanitizedStr(data_key='documentId',
|
2021-08-04 16:15:15 +00:00
|
|
|
required=False,
|
2021-07-21 06:35:18 +00:00
|
|
|
default='',
|
2021-07-29 13:46:49 +00:00
|
|
|
description=m.DataWipeDocument.id_document.comment)
|
2021-07-21 06:35:18 +00:00
|
|
|
file_name = SanitizedStr(data_key='filename',
|
|
|
|
default='',
|
2021-07-29 13:46:49 +00:00
|
|
|
description=m.DataWipeDocument.file_name.comment,
|
2021-07-21 06:35:18 +00:00
|
|
|
validate=validate.Length(max=100))
|
|
|
|
file_hash = SanitizedStr(data_key='hash',
|
|
|
|
default='',
|
2021-07-29 13:46:49 +00:00
|
|
|
description=m.DataWipeDocument.file_hash.comment,
|
2021-07-21 06:35:18 +00:00
|
|
|
validate=validate.Length(max=64))
|
2021-08-10 10:45:03 +00:00
|
|
|
|
|
|
|
@post_load
|
|
|
|
def get_trade_document(self, data):
|
|
|
|
data['document_type'] = 'DataWipeDocument'
|
|
|
|
|
|
|
|
|
|
|
|
class RecycleDocument(Thing):
|
|
|
|
__doc__ = m.DataWipeDocument.__doc__
|
|
|
|
file_hash = SanitizedStr(data_key='hash',
|
|
|
|
default='',
|
|
|
|
description=m.RecycleDocument.file_hash.comment,
|
|
|
|
validate=validate.Length(max=64))
|
|
|
|
weight = Float(required=False, validate=Range(0.1), description=m.RecycleDocument.weight.comment)
|
|
|
|
lot = NestedOn('Lot', only_query='id', description=m.RecycleDocument.lot.__doc__)
|
|
|
|
|
|
|
|
@post_load
|
|
|
|
def get_trade_document(self, data):
|
|
|
|
tradedocument = TradeDocument.query.filter_by(file_hash=data['file_hash']).one()
|
|
|
|
data['trade_document_id'] = tradedocument.id
|
|
|
|
data['file_name'] = tradedocument.file_name
|
|
|
|
data['date'] = tradedocument.date
|
|
|
|
data['id_document'] = tradedocument.id_document
|
|
|
|
data['url'] = tradedocument.url
|
|
|
|
data['document_type'] = 'RecycleDocument'
|