From 46da6c8982a8208967f7eaf77461a8149f5ca698 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 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/openedx_learning/apps/authoring/publishing/api.py b/openedx_learning/apps/authoring/publishing/api.py index 2d523377..aef49d67 100644 --- a/openedx_learning/apps/authoring/publishing/api.py +++ b/openedx_learning/apps/authoring/publishing/api.py @@ -216,10 +216,20 @@ def get_all_drafts(learning_package_id: int, /) -> QuerySet[Draft]: ) -def get_entities_with_unpublished_changes(learning_package_id: int, /) -> QuerySet[PublishableEntity]: - return PublishableEntity.objects \ - .filter(learning_package_id=learning_package_id) \ - .exclude(draft__version=F('published__version')) +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. + """ + query_filters = {"learning_package_id": learning_package_id} + if not include_deleted_drafts: + query_filters['draft__version__isnull'] = False + return PublishableEntity.objects.filter(**query_filters).exclude(draft__version=F('published__version')) def get_entities_with_unpublished_deletes(learning_package_id: int, /) -> QuerySet[PublishableEntity]: