2020-03-11 23:40:41 +00:00
|
|
|
from flask import current_app as app
|
2020-03-12 14:11:38 +00:00
|
|
|
from marshmallow import Schema as MarshmallowSchema, ValidationError, validates_schema
|
|
|
|
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-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-12 14:11:38 +00:00
|
|
|
ethereumHashes = SanitizedStr(default='', validate=Length(max=STR_BIG_SIZE))
|
|
|
|
url = URL(dump_only=True, description=m.Proof.url.__doc__)
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofTransfer(Proof):
|
|
|
|
__doc__ = m.ProofTransfer.__doc__
|
|
|
|
transfer = NestedOn(s_action.DisposeProduct,
|
2020-03-11 23:40:41 +00:00
|
|
|
required=True,
|
2020-03-12 14:11:38 +00:00
|
|
|
only_query='id')
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofDataWipe(Proof):
|
|
|
|
__doc__ = m.ProofDataWipe.__doc__
|
|
|
|
erasure_type = SanitizedStr(default='')
|
|
|
|
date = DateTime()
|
|
|
|
result = Boolean(missing=False)
|
|
|
|
erasure = NestedOn(s_action.EraseBasic, required=True, only_query='id')
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofFunction(Proof):
|
|
|
|
__doc__ = m.ProofFunction.__doc__
|
|
|
|
disk_usage = Integer()
|
|
|
|
rate = NestedOn(s_action.Rate, required=True, only_query='id')
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofReuse(Proof):
|
|
|
|
__doc__ = m.ProofReuse.__doc__
|
|
|
|
price = Integer()
|
2020-03-11 23:40:41 +00:00
|
|
|
|
|
|
|
|
2020-03-12 14:11:38 +00:00
|
|
|
class ProofRecycling(Proof):
|
|
|
|
__doc__ = m.ProofRecycling.__doc__
|
|
|
|
collection_point = SanitizedStr(default='')
|
|
|
|
date = DateTime()
|
|
|
|
contact = SanitizedStr(default='')
|
|
|
|
ticket = SanitizedStr(default='')
|
|
|
|
gps_location = SanitizedStr(default='')
|