clean code
This commit is contained in:
parent
73716a7331
commit
78c1f13260
|
@ -68,7 +68,8 @@ class Allocate(ActionWithMultipleDevices):
|
||||||
agent = NestedOn(s_agent.Agent, only_query='id', required=False, comment=m.Trade.to_comment)
|
agent = NestedOn(s_agent.Agent, only_query='id', required=False, comment=m.Trade.to_comment)
|
||||||
description = SanitizedStr(default='', description=m.Action.description.comment)
|
description = SanitizedStr(default='', description=m.Action.description.comment)
|
||||||
start_time = DateTime(data_key='start_time', description=m.Action.start_time.comment)
|
start_time = DateTime(data_key='start_time', description=m.Action.start_time.comment)
|
||||||
end_time = DateTime(data_key='end_time', description=m.Action.end_time.comment)
|
end_time = DateTime(data_key='end_time', required=False,
|
||||||
|
description=m.Action.end_time.comment)
|
||||||
code = SanitizedStr(data_key='Transaction', validate=Length(min=1, max=STR_BIG_SIZE),
|
code = SanitizedStr(data_key='Transaction', validate=Length(min=1, max=STR_BIG_SIZE),
|
||||||
required=False,
|
required=False,
|
||||||
description='The code of the agent to assigned.')
|
description='The code of the agent to assigned.')
|
||||||
|
@ -77,21 +78,18 @@ class Allocate(ActionWithMultipleDevices):
|
||||||
|
|
||||||
@validates_schema
|
@validates_schema
|
||||||
def validate_allocate(self, data: dict):
|
def validate_allocate(self, data: dict):
|
||||||
|
txt = "You need deallocate before allocate this device again"
|
||||||
for device in data['devices']:
|
for device in data['devices']:
|
||||||
|
if device.allocated == False:
|
||||||
|
device.allocated = True
|
||||||
|
continue
|
||||||
|
|
||||||
actions = [a for a in device.actions]
|
actions = [a for a in device.actions]
|
||||||
actions.sort(key=lambda x: x.created)
|
actions.sort(key=lambda x: x.created)
|
||||||
actions.reverse()
|
actions.reverse()
|
||||||
allocate = None
|
|
||||||
|
|
||||||
for a in actions:
|
for allocate in actions:
|
||||||
if isinstance(a, m.Allocate):
|
if isinstance(allocate, m.Allocate):
|
||||||
allocate = a
|
|
||||||
break
|
|
||||||
if isinstance(a, m.Deallocate):
|
|
||||||
break
|
|
||||||
|
|
||||||
if allocate:
|
|
||||||
txt = "You need deallocate before allocate this device again"
|
|
||||||
same_allocate = [
|
same_allocate = [
|
||||||
allocate.code == data['code'],
|
allocate.code == data['code'],
|
||||||
allocate.start_time == data['start_time'],
|
allocate.start_time == data['start_time'],
|
||||||
|
@ -99,12 +97,15 @@ class Allocate(ActionWithMultipleDevices):
|
||||||
]
|
]
|
||||||
if not all(same_allocate):
|
if not all(same_allocate):
|
||||||
raise ValidationError(txt)
|
raise ValidationError(txt)
|
||||||
|
if isinstance(allocate, m.Deallocate):
|
||||||
|
break
|
||||||
|
|
||||||
device.allocated = True
|
device.allocated = True
|
||||||
|
|
||||||
|
|
||||||
class Deallocate(ActionWithMultipleDevices):
|
class Deallocate(ActionWithMultipleDevices):
|
||||||
__doc__ = m.Deallocate.__doc__
|
__doc__ = m.Deallocate.__doc__
|
||||||
|
start_time = DateTime(data_key='start_time', description=m.Action.start_time.comment)
|
||||||
|
|
||||||
@validates_schema
|
@validates_schema
|
||||||
def validate_deallocate(self, data: dict):
|
def validate_deallocate(self, data: dict):
|
||||||
|
|
Reference in New Issue