Implement batch view
This commit is contained in:
parent
ac8375c98f
commit
c9f6217e42
|
@ -7,7 +7,8 @@ from teal.config import Config
|
||||||
from teal.enums import Currency
|
from teal.enums import Currency
|
||||||
from teal.utils import import_resource
|
from teal.utils import import_resource
|
||||||
|
|
||||||
from ereuse_devicehub.resources import action, agent, deliverynote, inventory, lot, tag, user
|
from ereuse_devicehub.resources import action, agent, deliverynote, inventory, \
|
||||||
|
lot, proof, tag, user
|
||||||
from ereuse_devicehub.resources.device import definitions
|
from ereuse_devicehub.resources.device import definitions
|
||||||
from ereuse_devicehub.resources.documents import documents
|
from ereuse_devicehub.resources.documents import documents
|
||||||
from ereuse_devicehub.resources.enums import PriceSoftware
|
from ereuse_devicehub.resources.enums import PriceSoftware
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
from teal.resource import Converters, Resource
|
from teal.resource import Converters, Resource
|
||||||
|
|
||||||
from ereuse_devicehub.resources.action import schemas
|
from ereuse_devicehub.resources.proof import schemas
|
||||||
from ereuse_devicehub.resources.proof.views import ProofView
|
from ereuse_devicehub.resources.proof.views import ProofView
|
||||||
|
|
||||||
|
|
||||||
class ProofDef(Resource):
|
class ProofDef(Resource):
|
||||||
SCHEMA = schemas.Proof
|
SCHEMA = schemas.Proof
|
||||||
VIEW = ProofView
|
VIEW = ProofView
|
||||||
AUTH = True
|
# AUTH = True
|
||||||
|
AUTH = False
|
||||||
ID_CONVERTER = Converters.uuid
|
ID_CONVERTER = Converters.uuid
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ from teal.resource import url_for_resource
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.action.models import Action, DisposeProduct, \
|
from ereuse_devicehub.resources.action.models import Action, DisposeProduct, \
|
||||||
EraseBasic, Rate
|
EraseBasic, Rate, Trade
|
||||||
from ereuse_devicehub.resources.models import Thing
|
from ereuse_devicehub.resources.models import Thing
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ class Proof(Thing):
|
||||||
|
|
||||||
|
|
||||||
class ProofTransfer(JoinedTableMixin, Proof):
|
class ProofTransfer(JoinedTableMixin, Proof):
|
||||||
transfer_id = Column(BigInteger, ForeignKey(Action.id), nullable=False)
|
transfer_id = Column(UUID, ForeignKey(Trade.id), nullable=False)
|
||||||
transfer = relationship(DisposeProduct,
|
transfer = relationship(DisposeProduct,
|
||||||
primaryjoin=DisposeProduct.id == transfer_id)
|
primaryjoin=DisposeProduct.id == transfer_id)
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ class ProofDataWipe(JoinedTableMixin, Proof):
|
||||||
erasure_type = Column(CIText())
|
erasure_type = Column(CIText())
|
||||||
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
||||||
result = db.Column(db.Boolean, default=False, nullable=False)
|
result = db.Column(db.Boolean, default=False, nullable=False)
|
||||||
erasure_id = Column(BigInteger, ForeignKey(EraseBasic.id), nullable=False)
|
erasure_id = Column(UUID, ForeignKey(EraseBasic.id), nullable=False)
|
||||||
erasure = relationship(EraseBasic,
|
erasure = relationship(EraseBasic,
|
||||||
backref=backref('proofs_datawipe',
|
backref=backref('proofs_datawipe',
|
||||||
lazy=True,
|
lazy=True,
|
||||||
|
@ -98,13 +98,13 @@ class ProofDataWipe(JoinedTableMixin, Proof):
|
||||||
|
|
||||||
class ProofFunction(JoinedTableMixin, Proof):
|
class ProofFunction(JoinedTableMixin, Proof):
|
||||||
disk_usage = db.Column(db.Integer, default=0)
|
disk_usage = db.Column(db.Integer, default=0)
|
||||||
rate_id = Column(BigInteger, ForeignKey(Rate.id), nullable=False)
|
rate_id = Column(UUID, ForeignKey(Rate.id), nullable=False)
|
||||||
rate = relationship(Rate,
|
rate = relationship(Rate,
|
||||||
primaryjoin=Rate.id == rate_id)
|
primaryjoin=Rate.id == rate_id)
|
||||||
|
|
||||||
|
|
||||||
class ProofReuse(JoinedTableMixin, Proof):
|
class ProofReuse(JoinedTableMixin, Proof):
|
||||||
price = db.Column(db.Integer, required=True)
|
price = db.Column(db.Integer)
|
||||||
|
|
||||||
|
|
||||||
class ProofRecycling(JoinedTableMixin, Proof):
|
class ProofRecycling(JoinedTableMixin, Proof):
|
||||||
|
|
|
@ -16,7 +16,8 @@ from ereuse_devicehub.resources.action import schemas as s_action
|
||||||
class Proof(Thing):
|
class Proof(Thing):
|
||||||
__doc__ = m.Proof.__doc__
|
__doc__ = m.Proof.__doc__
|
||||||
id = UUID(dump_only=True)
|
id = UUID(dump_only=True)
|
||||||
ethereumHashes = SanitizedStr(default='', validate=Length(max=STR_BIG_SIZE))
|
ethereum_hashes = SanitizedStr(default='', validate=Length(max=STR_BIG_SIZE),
|
||||||
|
data_key="ethereumHashes")
|
||||||
url = URL(dump_only=True, description=m.Proof.url.__doc__)
|
url = URL(dump_only=True, description=m.Proof.url.__doc__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ class ProofDataWipe(Proof):
|
||||||
erasure_type = SanitizedStr(default='')
|
erasure_type = SanitizedStr(default='')
|
||||||
date = DateTime()
|
date = DateTime()
|
||||||
result = Boolean(missing=False)
|
result = Boolean(missing=False)
|
||||||
erasure = NestedOn(s_action.EraseBasic, required=True, only_query='id')
|
erasure = NestedOn(s_action.EraseBasic, dump_only=True, only_query='id')
|
||||||
|
|
||||||
|
|
||||||
class ProofFunction(Proof):
|
class ProofFunction(Proof):
|
||||||
|
|
|
@ -24,15 +24,16 @@ class ProofView(View):
|
||||||
raise ValidationError('JSON is not correct.')
|
raise ValidationError('JSON is not correct.')
|
||||||
# todo there should be a way to better get subclassess resource
|
# todo there should be a way to better get subclassess resource
|
||||||
# defs
|
# defs
|
||||||
|
proofs = list()
|
||||||
if json['batch']:
|
if json['batch']:
|
||||||
for proof in json['proofs']:
|
for prf in json['proofs']:
|
||||||
resource_def = app.resources[proof['type']]
|
resource_def = app.resources[prf['type']]
|
||||||
a = resource_def.schema.load(json)
|
p = resource_def.schema.load(prf)
|
||||||
Model = db.Model._decl_class_registry.data[json['type']]()
|
Model = db.Model._decl_class_registry.data[prf['type']]()
|
||||||
action = Model(**a)
|
proof = Model(**p)
|
||||||
db.session.add(action)
|
db.session.add(proof)
|
||||||
db.session().final_flush()
|
proofs.append(self.schema.dump(proof))
|
||||||
ret = self.schema.jsonify(action)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
ret = self.schema.jsonify(proofs)
|
||||||
ret.status_code = 201
|
ret.status_code = 201
|
||||||
return ret
|
return ret
|
||||||
|
|
Reference in New Issue