2020-03-11 23:40:41 +00:00
|
|
|
from flask import current_app as app
|
2020-03-23 17:49:22 +00:00
|
|
|
from marshmallow import Schema as MarshmallowSchema, ValidationError, fields as f, validates_schema
|
2020-03-12 14:11:38 +00:00
|
|
|
from marshmallow.fields import Boolean, DateTime, Integer, Nested, String, UUID
|
|
|
|
from marshmallow.validate import Length
|
2020-03-11 23:40:41 +00:00
|
|
|
from sqlalchemy.util import OrderedSet
|
2020-03-12 14:11:38 +00:00
|
|
|
from teal.marshmallow import SanitizedStr, URL
|
2020-03-11 23:40:41 +00:00
|
|
|
from teal.resource import Schema
|
|
|
|
|
|
|
|
from ereuse_devicehub.marshmallow import NestedOn
|
2020-03-12 14:11:38 +00:00
|
|
|
from ereuse_devicehub.resources.proof import models as m
|
2020-03-11 23:40:41 +00:00
|
|
|
from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE
|
|
|
|
from ereuse_devicehub.resources.schemas import Thing
|
2020-03-12 14:11:38 +00:00
|
|
|
from ereuse_devicehub.resources.action import schemas as s_action
|
2020-03-17 01:03:48 +00:00
|
|
|
from ereuse_devicehub.resources.device import schemas as s_device
|
2020-03-20 22:57:30 +00:00
|
|
|
from ereuse_devicehub.resources.user import schemas as s_user
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Proof(Thing):
|
2020-03-12 14:11:38 +00:00
|
|
|
__doc__ = m.Proof.__doc__
|
2020-03-11 23:40:41 +00:00
|
|
|
id = UUID(dump_only=True)
|
2020-03-16 23:57:14 +00:00
|
|
|
ethereum_hash = SanitizedStr(default='', validate=Length(max=STR_BIG_SIZE),
|
|
|
|
data_key="ethereumHash", required=True)
|
2020-03-12 14:11:38 +00:00
|
|
|
url = URL(dump_only=True, description=m.Proof.url.__doc__)
|
2020-03-24 21:34:53 +00:00
|
|
|
device_id = Integer(load_only=True, data_key='deviceID')
|
|
|
|
device = NestedOn(s_device.Device, dump_only=True)
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofTransfer(Proof):
|
|
|
|
__doc__ = m.ProofTransfer.__doc__
|
2020-03-24 21:34:53 +00:00
|
|
|
deposit = Integer(validate=f.validate.Range(min=0, max=100))
|
|
|
|
supplier_id = UUID(load_only=True, required=True, data_key='supplierID')
|
|
|
|
receiver_id = UUID(load_only=True, required=True, data_key='receiverID')
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofDataWipe(Proof):
|
|
|
|
__doc__ = m.ProofDataWipe.__doc__
|
2020-03-24 21:34:53 +00:00
|
|
|
# erasure_type = String(default='', data_key='erasureType')
|
2020-03-15 23:26:20 +00:00
|
|
|
date = DateTime('iso', required=True)
|
2020-03-16 23:57:14 +00:00
|
|
|
result = Boolean(required=True)
|
2020-03-24 21:34:53 +00:00
|
|
|
proof_author_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE),
|
2020-03-25 14:38:29 +00:00
|
|
|
load_only=True, required=True, data_key='proofAuthorID')
|
2020-03-24 21:34:53 +00:00
|
|
|
proof_author = NestedOn(s_user.User, dump_only=True)
|
2020-03-16 23:57:14 +00:00
|
|
|
erasure = NestedOn(s_action.EraseBasic, only_query='id', data_key='erasureID')
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofFunction(Proof):
|
|
|
|
__doc__ = m.ProofFunction.__doc__
|
2020-03-24 21:34:53 +00:00
|
|
|
disk_usage = Integer(validate=f.validate.Range(min=0, max=100), data_key='diskUsage')
|
|
|
|
proof_author_id = SanitizedStr(validate=f.validate.Length(max=STR_SIZE),
|
2020-03-25 14:38:29 +00:00
|
|
|
load_only=True, required=True, data_key='proofAuthorID')
|
2020-03-24 21:34:53 +00:00
|
|
|
proof_author = NestedOn(s_user.User, dump_only=True)
|
2020-03-17 22:36:27 +00:00
|
|
|
rate = NestedOn(s_action.Rate, required=True,
|
|
|
|
only_query='id', data_key='rateID')
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofReuse(Proof):
|
|
|
|
__doc__ = m.ProofReuse.__doc__
|
2020-03-20 22:57:30 +00:00
|
|
|
receiver_segment = String(default='', data_key='receiverSegment', required=True)
|
|
|
|
id_receipt = String(default='', data_key='idReceipt', required=True)
|
2020-03-27 10:48:16 +00:00
|
|
|
supplier_id = UUID(load_only=True, required=False, data_key='supplierID')
|
|
|
|
receiver_id = UUID(load_only=True, required=False, data_key='receiverID')
|
2020-03-20 22:57:30 +00:00
|
|
|
price = Integer(required=True)
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofRecycling(Proof):
|
|
|
|
__doc__ = m.ProofRecycling.__doc__
|
2020-03-17 22:45:23 +00:00
|
|
|
collection_point = SanitizedStr(default='', data_key='collectionPoint', required=True)
|
|
|
|
date = DateTime('iso', required=True)
|
|
|
|
contact = SanitizedStr(default='', required=True)
|
|
|
|
ticket = SanitizedStr(default='', required=True)
|
|
|
|
gps_location = SanitizedStr(default='', data_key='gpsLocation', required=True)
|
|
|
|
recycler_code = SanitizedStr(default='', data_key='recyclerCode', required=True)
|