Skip to content

Commit

Permalink
Finish 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dgk committed Nov 23, 2016
2 parents ec1e66d + 74f5bba commit c30a410
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion business_logic/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ def add_root(cls, **kwargs):
return super(Node, cls).add_root(**kwargs)

def delete(self):
if self.object_id and self.content_object:
if (
self.object_id and
self.content_object and
self.content_type.app_label == ContentType.objects.get_for_model(self.__class__).app_label
):
self.content_object.delete()

for child in self.get_children():
child.delete()

return super(Node, self).delete()

def add_child(self, **kwargs):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ def test_delete_with_lost_content_object(self):

root.delete()

def test_node_deletion_should_not_delete_content_objects_from_other_apps(self):
root = Node.add_root()
test_model = TestModel.objects.create()
root.add_child(content_object=test_model)
root = Node.objects.get(id=root.id)

root.delete()

self.assertTrue(TestModel.objects.filter(id=test_model.id))
self.assertFalse(Node.objects.all())

def test_statement_or_block(self):
root = Node.add_root()
self.failUnless(root.is_block())
Expand Down

0 comments on commit c30a410

Please sign in to comment.