fix components placeholder in unbinding
This commit is contained in:
parent
fc86181311
commit
2a32ba47b8
|
@ -382,11 +382,13 @@ class UnBindingView(GenericMixin):
|
|||
return flask.render_template(self.template_name, **self.context)
|
||||
|
||||
def clone_device(self, device):
|
||||
if device.binding.is_abstract:
|
||||
if device.binding and device.binding.is_abstract:
|
||||
return
|
||||
|
||||
kangaroo = device.binding.kangaroo
|
||||
device.binding.kangaroo = False
|
||||
kangaroo = False
|
||||
if device.binding:
|
||||
kangaroo = device.binding.kangaroo
|
||||
device.binding.kangaroo = False
|
||||
|
||||
dict_device = copy.copy(device.__dict__)
|
||||
dict_device.pop('_sa_instance_state')
|
||||
|
@ -406,6 +408,9 @@ class UnBindingView(GenericMixin):
|
|||
for c in device.components:
|
||||
if c.binding:
|
||||
c.binding.device.parent = new_device
|
||||
else:
|
||||
new_c = self.clone_device(c)
|
||||
new_c.parent = new_device
|
||||
|
||||
placeholder = Placeholder(
|
||||
device=new_device, binding=device, is_abstract=True, kangaroo=kangaroo
|
||||
|
|
|
@ -2247,9 +2247,11 @@ def test_unbinding(user3: UserClientFlask):
|
|||
user3.get(uri)
|
||||
|
||||
# action binding
|
||||
assert Placeholder.query.count() == 11
|
||||
assert dev.placeholder.binding is None
|
||||
user3.post(uri, data={})
|
||||
assert dev.placeholder.binding == dev_wb
|
||||
assert Placeholder.query.count() == 1
|
||||
|
||||
dhid = dev.dhid
|
||||
# action unbinding
|
||||
|
@ -2273,6 +2275,7 @@ def test_unbinding(user3: UserClientFlask):
|
|||
assert Device.query.filter_by(id=dev_wb.binding.device.id).first()
|
||||
assert Device.query.filter_by(id=dev.id).first()
|
||||
assert Placeholder.query.filter_by(id=dev.placeholder.id).first()
|
||||
assert Placeholder.query.count() == 11
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
|
Reference in a new issue