First implementation of batch POST of ProofDataWipe
This commit is contained in:
parent
c9f6217e42
commit
0d9dccda47
|
@ -49,10 +49,6 @@ class Proof(Thing):
|
||||||
"""The URL where to GET this proof."""
|
"""The URL where to GET this proof."""
|
||||||
return urlutils.URL(url_for_resource(Proof, item_id=self.id))
|
return urlutils.URL(url_for_resource(Proof, item_id=self.id))
|
||||||
|
|
||||||
@property
|
|
||||||
def certificate(self) -> Optional[urlutils.URL]:
|
|
||||||
return None
|
|
||||||
|
|
||||||
# noinspection PyMethodParameters
|
# noinspection PyMethodParameters
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def __mapper_args__(cls):
|
def __mapper_args__(cls):
|
||||||
|
@ -81,35 +77,43 @@ class Proof(Thing):
|
||||||
class ProofTransfer(JoinedTableMixin, Proof):
|
class ProofTransfer(JoinedTableMixin, Proof):
|
||||||
transfer_id = Column(UUID, ForeignKey(Trade.id), nullable=False)
|
transfer_id = Column(UUID, ForeignKey(Trade.id), nullable=False)
|
||||||
transfer = relationship(DisposeProduct,
|
transfer = relationship(DisposeProduct,
|
||||||
|
backref=backref("proof_transfer",
|
||||||
|
lazy=True,
|
||||||
|
cascade=CASCADE_OWN),
|
||||||
|
uselist=False,
|
||||||
primaryjoin=DisposeProduct.id == transfer_id)
|
primaryjoin=DisposeProduct.id == transfer_id)
|
||||||
|
|
||||||
|
|
||||||
class ProofDataWipe(JoinedTableMixin, Proof):
|
class ProofDataWipe(JoinedTableMixin, Proof):
|
||||||
erasure_type = Column(CIText())
|
erasure_type = Column(CIText(), default='', nullable=False)
|
||||||
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
date = Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||||
result = db.Column(db.Boolean, default=False, nullable=False)
|
result = Column(db.Boolean, default=False, nullable=False)
|
||||||
erasure_id = Column(UUID, ForeignKey(EraseBasic.id), 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,
|
erasure = relationship(EraseBasic,
|
||||||
backref=backref('proofs_datawipe',
|
backref=backref('proof_datawipe',
|
||||||
lazy=True,
|
lazy=True,
|
||||||
cascade=CASCADE_OWN),
|
cascade=CASCADE_OWN),
|
||||||
primaryjoin=EraseBasic.id == erasure_id)
|
primaryjoin=EraseBasic.id == erasure_id)
|
||||||
|
|
||||||
|
|
||||||
class ProofFunction(JoinedTableMixin, Proof):
|
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_id = Column(UUID, ForeignKey(Rate.id), nullable=False)
|
||||||
rate = relationship(Rate,
|
rate = relationship(Rate,
|
||||||
|
backref=backref('proof_function',
|
||||||
|
lazy=True,
|
||||||
|
cascade=CASCADE_OWN),
|
||||||
primaryjoin=Rate.id == rate_id)
|
primaryjoin=Rate.id == rate_id)
|
||||||
|
|
||||||
|
|
||||||
class ProofReuse(JoinedTableMixin, Proof):
|
class ProofReuse(JoinedTableMixin, Proof):
|
||||||
price = db.Column(db.Integer)
|
price = Column(db.Integer)
|
||||||
|
|
||||||
|
|
||||||
class ProofRecycling(JoinedTableMixin, Proof):
|
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)
|
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||||
contact = Column(CIText())
|
contact = Column(CIText(), default='', nullable=False)
|
||||||
ticket = Column(CIText())
|
ticket = Column(CIText(), default='', nullable=False)
|
||||||
gps_location = Column(CIText())
|
gps_location = Column(CIText(), default='', nullable=False)
|
||||||
|
|
|
@ -31,9 +31,9 @@ class ProofTransfer(Proof):
|
||||||
class ProofDataWipe(Proof):
|
class ProofDataWipe(Proof):
|
||||||
__doc__ = m.ProofDataWipe.__doc__
|
__doc__ = m.ProofDataWipe.__doc__
|
||||||
erasure_type = SanitizedStr(default='')
|
erasure_type = SanitizedStr(default='')
|
||||||
date = DateTime()
|
date = DateTime('iso', required=True)
|
||||||
result = Boolean(missing=False)
|
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):
|
class ProofFunction(Proof):
|
||||||
|
|
|
@ -2,12 +2,13 @@ from distutils.version import StrictVersion
|
||||||
from typing import List
|
from typing import List
|
||||||
from uuid import UUID
|
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 sqlalchemy.util import OrderedSet
|
||||||
from teal.marshmallow import ValidationError
|
from teal.marshmallow import ValidationError
|
||||||
from teal.resource import View
|
from teal.resource import View
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
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.models import Action, RateComputer, Snapshot, VisualTest
|
||||||
from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate
|
from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate
|
||||||
from ereuse_devicehub.resources.device.models import Component, Computer
|
from ereuse_devicehub.resources.device.models import Component, Computer
|
||||||
|
@ -34,6 +35,9 @@ class ProofView(View):
|
||||||
db.session.add(proof)
|
db.session.add(proof)
|
||||||
proofs.append(self.schema.dump(proof))
|
proofs.append(self.schema.dump(proof))
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
ret = self.schema.jsonify(proofs)
|
response = jsonify({
|
||||||
ret.status_code = 201
|
'items': proofs,
|
||||||
return ret
|
'url': request.path
|
||||||
|
})
|
||||||
|
response.status_code = 201
|
||||||
|
return response
|
||||||
|
|
Reference in New Issue