From fbf8862ec5adbe8c35ca7bee6c722d33fbe9e1d4 Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Wed, 7 Aug 2024 15:42:09 +0530 Subject: [PATCH] feat: option to include deleted drafts while fetching unpublished entities By default, this is set to False. --- .../apps/authoring/publishing/api.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/openedx_learning/apps/authoring/publishing/api.py b/openedx_learning/apps/authoring/publishing/api.py index 2d523377..e0421041 100644 --- a/openedx_learning/apps/authoring/publishing/api.py +++ b/openedx_learning/apps/authoring/publishing/api.py @@ -216,10 +216,21 @@ def get_all_drafts(learning_package_id: int, /) -> QuerySet[Draft]: ) -def get_entities_with_unpublished_changes(learning_package_id: int, /) -> QuerySet[PublishableEntity]: +def get_entities_with_unpublished_changes( + learning_package_id: int, + /, + include_deleted_drafts: bool = False +) -> QuerySet[PublishableEntity]: + """ + Fetch entities that have unpublished changes. + + By default, this excludes soft-deleted drafts but can be included using include_deleted_drafts option. + """ return PublishableEntity.objects \ - .filter(learning_package_id=learning_package_id) \ - .exclude(draft__version=F('published__version')) + .filter( + learning_package_id=learning_package_id, + draft__version__isnull=include_deleted_drafts, + ).exclude(draft__version=F('published__version')) def get_entities_with_unpublished_deletes(learning_package_id: int, /) -> QuerySet[PublishableEntity]: