♻️(backend) refactor list view to allow filtering other views
the "filter_queryset" method is called in the middle of the "get_object" method. We use the "get_object" in actions like "children", "tree", etc. which start by calling "get_object" but return lists of documents. We would like to apply filters to these views but the it didn't work because the "get_object" method was also impacted by the filters... In a future PR, we should take control of the "get_object" method and decouple all this. We need a quick solution to allow releasing the hierchical documents feature in the frontend.
This commit is contained in:
committed by
Manuel Raynaud
parent
0aabf26694
commit
56aa69f56a
@@ -809,17 +809,18 @@ class Document(MP_Node, BaseModel):
|
||||
Soft delete the document, marking the deletion on descendants.
|
||||
We still keep the .delete() method untouched for programmatic purposes.
|
||||
"""
|
||||
if self.deleted_at or self.ancestors_deleted_at:
|
||||
if (
|
||||
self._meta.model.objects.filter(
|
||||
models.Q(deleted_at__isnull=False)
|
||||
| models.Q(ancestors_deleted_at__isnull=False),
|
||||
pk=self.pk,
|
||||
).exists()
|
||||
or self.get_ancestors().filter(deleted_at__isnull=False).exists()
|
||||
):
|
||||
raise RuntimeError(
|
||||
"This document is already deleted or has deleted ancestors."
|
||||
)
|
||||
|
||||
# Check if any ancestors are deleted
|
||||
if self.get_ancestors().filter(deleted_at__isnull=False).exists():
|
||||
raise RuntimeError(
|
||||
"Cannot delete this document because one or more ancestors are already deleted."
|
||||
)
|
||||
|
||||
self.ancestors_deleted_at = self.deleted_at = timezone.now()
|
||||
self.save()
|
||||
|
||||
@@ -836,14 +837,8 @@ class Document(MP_Node, BaseModel):
|
||||
raise ValidationError({"deleted_at": [_("This document is not deleted.")]})
|
||||
|
||||
if self.deleted_at < get_trashbin_cutoff():
|
||||
raise ValidationError(
|
||||
{
|
||||
"deleted_at": [
|
||||
_(
|
||||
"This document was permanently deleted and cannot be restored."
|
||||
)
|
||||
]
|
||||
}
|
||||
raise RuntimeError(
|
||||
"This document was permanently deleted and cannot be restored."
|
||||
)
|
||||
|
||||
# save the current deleted_at value to exclude it from the descendants update
|
||||
|
||||
Reference in New Issue
Block a user