2020-03-11 23:40:41 +00:00
|
|
|
from distutils.version import StrictVersion
|
|
|
|
from typing import List
|
|
|
|
from uuid import UUID
|
|
|
|
|
2020-03-15 23:26:20 +00:00
|
|
|
from flask import current_app as app, request, jsonify
|
2020-03-11 23:40:41 +00:00
|
|
|
from sqlalchemy.util import OrderedSet
|
|
|
|
from teal.marshmallow import ValidationError
|
|
|
|
from teal.resource import View
|
|
|
|
|
|
|
|
from ereuse_devicehub.db import db
|
2020-03-15 23:26:20 +00:00
|
|
|
from ereuse_devicehub.query import things_response
|
2020-03-11 23:40:41 +00:00
|
|
|
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
|
|
|
|
from ereuse_devicehub.resources.enums import SnapshotSoftware
|
|
|
|
|
|
|
|
SUPPORTED_WORKBENCH = StrictVersion('11.0')
|
|
|
|
|
|
|
|
|
|
|
|
class ProofView(View):
|
|
|
|
def post(self):
|
|
|
|
"""Posts batches of proofs."""
|
|
|
|
json = request.get_json(validate=False)
|
|
|
|
if not json:
|
|
|
|
raise ValidationError('JSON is not correct.')
|
|
|
|
# todo there should be a way to better get subclassess resource
|
|
|
|
# defs
|
2020-03-12 16:07:35 +00:00
|
|
|
proofs = list()
|
2020-03-11 23:40:41 +00:00
|
|
|
if json['batch']:
|
2020-03-12 16:07:35 +00:00
|
|
|
for prf in json['proofs']:
|
|
|
|
resource_def = app.resources[prf['type']]
|
|
|
|
p = resource_def.schema.load(prf)
|
|
|
|
Model = db.Model._decl_class_registry.data[prf['type']]()
|
|
|
|
proof = Model(**p)
|
|
|
|
db.session.add(proof)
|
2020-03-17 01:03:48 +00:00
|
|
|
db.session.commit()
|
2020-03-12 16:07:35 +00:00
|
|
|
proofs.append(self.schema.dump(proof))
|
2020-03-15 23:26:20 +00:00
|
|
|
response = jsonify({
|
|
|
|
'items': proofs,
|
|
|
|
'url': request.path
|
|
|
|
})
|
|
|
|
response.status_code = 201
|
|
|
|
return response
|