First implementation of batch POST of ProofDataWipe

This commit is contained in:
yiorgos marinellis 2020-03-16 00:26:20 +01:00
parent c9f6217e42
commit 0d9dccda47
3 changed files with 29 additions and 21 deletions

View file

@ -49,10 +49,6 @@ class Proof(Thing):
"""The URL where to GET this proof."""
return urlutils.URL(url_for_resource(Proof, item_id=self.id))
@property
def certificate(self) -> Optional[urlutils.URL]:
return None
# noinspection PyMethodParameters
@declared_attr
def __mapper_args__(cls):
@ -81,35 +77,43 @@ class Proof(Thing):
class ProofTransfer(JoinedTableMixin, Proof):
transfer_id = Column(UUID, ForeignKey(Trade.id), nullable=False)
transfer = relationship(DisposeProduct,
backref=backref("proof_transfer",
lazy=True,
cascade=CASCADE_OWN),
uselist=False,
primaryjoin=DisposeProduct.id == transfer_id)
class ProofDataWipe(JoinedTableMixin, Proof):
erasure_type = Column(CIText())
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
result = db.Column(db.Boolean, default=False, nullable=False)
erasure_id = Column(UUID, ForeignKey(EraseBasic.id), nullable=False)
erasure_type = Column(CIText(), default='', nullable=False)
date = Column(db.DateTime, nullable=False, default=datetime.utcnow)
result = Column(db.Boolean, default=False, nullable=False)
result.comment = """Identifies proof datawipe as a result."""
erasure_id = Column(UUID(as_uuid=True), ForeignKey(EraseBasic.id), nullable=False)
erasure = relationship(EraseBasic,
backref=backref('proofs_datawipe',
backref=backref('proof_datawipe',
lazy=True,
cascade=CASCADE_OWN),
primaryjoin=EraseBasic.id == erasure_id)
class ProofFunction(JoinedTableMixin, Proof):
disk_usage = db.Column(db.Integer, default=0)
disk_usage = Column(db.Integer, default=0)
rate_id = Column(UUID, ForeignKey(Rate.id), nullable=False)
rate = relationship(Rate,
backref=backref('proof_function',
lazy=True,
cascade=CASCADE_OWN),
primaryjoin=Rate.id == rate_id)
class ProofReuse(JoinedTableMixin, Proof):
price = db.Column(db.Integer)
price = Column(db.Integer)
class ProofRecycling(JoinedTableMixin, Proof):
collection_point = Column(CIText())
collection_point = Column(CIText(), default='', nullable=False)
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
contact = Column(CIText())
ticket = Column(CIText())
gps_location = Column(CIText())
contact = Column(CIText(), default='', nullable=False)
ticket = Column(CIText(), default='', nullable=False)
gps_location = Column(CIText(), default='', nullable=False)

View file

@ -31,9 +31,9 @@ class ProofTransfer(Proof):
class ProofDataWipe(Proof):
__doc__ = m.ProofDataWipe.__doc__
erasure_type = SanitizedStr(default='')
date = DateTime()
date = DateTime('iso', required=True)
result = Boolean(missing=False)
erasure = NestedOn(s_action.EraseBasic, dump_only=True, only_query='id')
erasure = NestedOn(s_action.EraseBasic, only_query='id')
class ProofFunction(Proof):

View file

@ -2,12 +2,13 @@ from distutils.version import StrictVersion
from typing import List
from uuid import UUID
from flask import current_app as app, request
from flask import current_app as app, request, jsonify
from sqlalchemy.util import OrderedSet
from teal.marshmallow import ValidationError
from teal.resource import View
from ereuse_devicehub.db import db
from ereuse_devicehub.query import things_response
from ereuse_devicehub.resources.action.models import Action, RateComputer, Snapshot, VisualTest
from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate
from ereuse_devicehub.resources.device.models import Component, Computer
@ -34,6 +35,9 @@ class ProofView(View):
db.session.add(proof)
proofs.append(self.schema.dump(proof))
db.session.commit()
ret = self.schema.jsonify(proofs)
ret.status_code = 201
return ret
response = jsonify({
'items': proofs,
'url': request.path
})
response.status_code = 201
return response