From 7f0de81f3fe70d3fbaf9115c7f2a212bf337b56e Mon Sep 17 00:00:00 2001 From: Andy Babic Date: Fri, 13 Dec 2024 13:18:47 +0000 Subject: [PATCH] Return early to reduce indentation in retry_file_permission_set_attempts command --- cms/private_media/bulk_operations.py | 2 +- .../retry_file_permission_set_attempts.py | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cms/private_media/bulk_operations.py b/cms/private_media/bulk_operations.py index add4a8cb..7456139f 100644 --- a/cms/private_media/bulk_operations.py +++ b/cms/private_media/bulk_operations.py @@ -1,6 +1,6 @@ import concurrent.futures import logging -from collections.abc import Callable, Iterable +from collections.abc import Iterable from typing import TYPE_CHECKING from django.conf import settings diff --git a/cms/private_media/management/commands/retry_file_permission_set_attempts.py b/cms/private_media/management/commands/retry_file_permission_set_attempts.py index 3734e354..1267876d 100644 --- a/cms/private_media/management/commands/retry_file_permission_set_attempts.py +++ b/cms/private_media/management/commands/retry_file_permission_set_attempts.py @@ -34,17 +34,19 @@ def handle(self, *args: Any, **options: Any) -> None: queryset = queryset.prefetch_related("renditions") permissions_outdated = list(queryset) self.stdout.write(f"{len(permissions_outdated)} {model.__name__} instances have outdated file permissions.") - if permissions_outdated: - make_private = [] - make_public = [] - for obj in permissions_outdated: - if obj.privacy is Privacy.PRIVATE: - make_private.append(obj) - elif obj.privacy is Privacy.PUBLIC: - make_public.append(obj) + if not permissions_outdated: + continue - self.update_file_permissions(model, make_private, Privacy.PRIVATE) - self.update_file_permissions(model, make_public, Privacy.PUBLIC) + make_private = [] + make_public = [] + for obj in permissions_outdated: + if obj.privacy is Privacy.PRIVATE: + make_private.append(obj) + elif obj.privacy is Privacy.PUBLIC: + make_public.append(obj) + + self.update_file_permissions(model, make_private, Privacy.PRIVATE) + self.update_file_permissions(model, make_public, Privacy.PUBLIC) def update_file_permissions( self, model_class: type["PrivateMediaMixin"], items: list["PrivateMediaMixin"], privacy: Privacy