Merge pull request #385 from eReuse/bugfix/3957-unbinding
fix components placeholder in unbinding
This commit is contained in:
commit
f33499cb23
|
@ -382,11 +382,13 @@ class UnBindingView(GenericMixin):
|
||||||
return flask.render_template(self.template_name, **self.context)
|
return flask.render_template(self.template_name, **self.context)
|
||||||
|
|
||||||
def clone_device(self, device):
|
def clone_device(self, device):
|
||||||
if device.binding.is_abstract:
|
if device.binding and device.binding.is_abstract:
|
||||||
return
|
return
|
||||||
|
|
||||||
kangaroo = device.binding.kangaroo
|
kangaroo = False
|
||||||
device.binding.kangaroo = False
|
if device.binding:
|
||||||
|
kangaroo = device.binding.kangaroo
|
||||||
|
device.binding.kangaroo = False
|
||||||
|
|
||||||
dict_device = copy.copy(device.__dict__)
|
dict_device = copy.copy(device.__dict__)
|
||||||
dict_device.pop('_sa_instance_state')
|
dict_device.pop('_sa_instance_state')
|
||||||
|
@ -406,6 +408,9 @@ class UnBindingView(GenericMixin):
|
||||||
for c in device.components:
|
for c in device.components:
|
||||||
if c.binding:
|
if c.binding:
|
||||||
c.binding.device.parent = new_device
|
c.binding.device.parent = new_device
|
||||||
|
else:
|
||||||
|
new_c = self.clone_device(c)
|
||||||
|
new_c.parent = new_device
|
||||||
|
|
||||||
placeholder = Placeholder(
|
placeholder = Placeholder(
|
||||||
device=new_device, binding=device, is_abstract=True, kangaroo=kangaroo
|
device=new_device, binding=device, is_abstract=True, kangaroo=kangaroo
|
||||||
|
|
|
@ -2255,9 +2255,11 @@ def test_unbinding(user3: UserClientFlask):
|
||||||
user3.get(uri)
|
user3.get(uri)
|
||||||
|
|
||||||
# action binding
|
# action binding
|
||||||
|
assert Placeholder.query.count() == 11
|
||||||
assert dev.placeholder.binding is None
|
assert dev.placeholder.binding is None
|
||||||
user3.post(uri, data={})
|
user3.post(uri, data={})
|
||||||
assert dev.placeholder.binding == dev_wb
|
assert dev.placeholder.binding == dev_wb
|
||||||
|
assert Placeholder.query.count() == 1
|
||||||
|
|
||||||
dhid = dev.dhid
|
dhid = dev.dhid
|
||||||
# action unbinding
|
# action unbinding
|
||||||
|
@ -2281,6 +2283,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_wb.binding.device.id).first()
|
||||||
assert Device.query.filter_by(id=dev.id).first()
|
assert Device.query.filter_by(id=dev.id).first()
|
||||||
assert Placeholder.query.filter_by(id=dev.placeholder.id).first()
|
assert Placeholder.query.filter_by(id=dev.placeholder.id).first()
|
||||||
|
assert Placeholder.query.count() == 11
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
|
Reference in New Issue