Propagates PATCH /lot updates to the involved devices
This commit is contained in:
parent
8be56c93f9
commit
5748a45d2c
|
@ -10,10 +10,11 @@ from flask import Response, jsonify, request
|
||||||
from marshmallow import Schema as MarshmallowSchema, fields as f
|
from marshmallow import Schema as MarshmallowSchema, fields as f
|
||||||
from teal.marshmallow import EnumField
|
from teal.marshmallow import EnumField
|
||||||
from teal.resource import View
|
from teal.resource import View
|
||||||
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.query import things_response
|
from ereuse_devicehub.query import things_response
|
||||||
from ereuse_devicehub.resources.device.models import Device
|
from ereuse_devicehub.resources.device.models import Device, Computer
|
||||||
from ereuse_devicehub.resources.lot.models import Lot, Path
|
from ereuse_devicehub.resources.lot.models import Lot, Path
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,16 +41,16 @@ class LotView(View):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def patch(self, id):
|
def patch(self, id):
|
||||||
patch_schema = self.resource_def.SCHEMA(only=('name', 'description', 'transfer_state', 'receiver_id', 'deposit', 'delivery_note_address'), partial=True)
|
patch_schema = self.resource_def.SCHEMA(only=('name', 'description', 'transfer_state', 'receiver_id', 'deposit', 'delivery_note_address', 'devices'), partial=True)
|
||||||
l = request.get_json(schema=patch_schema)
|
l = request.get_json(schema=patch_schema)
|
||||||
lot = Lot.query.filter_by(id=id).one()
|
lot = Lot.query.filter_by(id=id).one()
|
||||||
if lot.transfer_state.name == 'Initial':
|
device_fields = ['transfer_state', 'receiver_id', 'deposit', 'delivery_note_address']
|
||||||
# Initial lot transfer state case
|
computers = [x for x in lot.all_devices if isinstance(x, Computer)]
|
||||||
# deposit = self.get_lot_deposit(lot)
|
|
||||||
# Do something with deposit variable
|
|
||||||
pass
|
|
||||||
for key, value in l.items():
|
for key, value in l.items():
|
||||||
setattr(lot, key, value)
|
setattr(lot, key, value)
|
||||||
|
if key in device_fields:
|
||||||
|
for dev in computers:
|
||||||
|
setattr(dev, key, value)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return Response(status=204)
|
return Response(status=204)
|
||||||
|
|
||||||
|
|
Reference in New Issue