Perform page deletion on the base Page class, not page.specific

This avoids a treebeard bug where calling SpecificPage.delete() would fail to delete child pages that are not instances of SpecificPage.

This partially reverts #737, and adds logic at the model level to ensure that any other calls to SpecificPage.delete() get diverted to Page.delete() instead. Re the rationale given in #737, reverting this is legitimate (and does not cause any meaningful regression) because:
1) Django always fires pre/post delete signals from both Page and SpecificPage regardless of which one is deleted;
2) Overriding delete() can never reliably work whatever we do; even if we consistently call SpecificPage.delete() within wagtail, we can't get treebeard to do that for child pages because treebeard has no knowledge of how to obtain a SpecificPage instance.
pull/1232/head
Matt Westcott 2015-03-04 16:16:06 +00:00 zatwierdzone przez Karl Hobley
rodzic 94620983bc
commit bd588a654d
2 zmienionych plików z 12 dodań i 1 usunięć

Wyświetl plik

@ -375,7 +375,7 @@ def edit(request, page_id):
@permission_required('wagtailadmin.access_admin')
def delete(request, page_id):
page = get_object_or_404(Page, id=page_id).specific
page = get_object_or_404(Page, id=page_id)
if not page.permissions_for_user(request.user).can_delete():
raise PermissionDenied

Wyświetl plik

@ -366,6 +366,17 @@ class Page(six.with_metaclass(PageBase, MP_Node, ClusterableModel, index.Indexed
return result
def delete(self, *args, **kwargs):
# Ensure that deletion always happens on an instance of Page, not a specific subclass. This
# works around a bug in treebeard <= 3.0 where calling SpecificPage.delete() fails to delete
# child pages that are not instances of SpecificPage
if type(self) is Page:
# this is a Page instance, so carry on as we were
return super(Page, self).delete(*args, **kwargs)
else:
# retrieve an actual Page instance and delete that instead of self
return Page.objects.get(id=self.id).delete(*args, **kwargs)
@classmethod
def check(cls, **kwargs):
errors = super(Page, cls).check(**kwargs)