From 62f4dc288d6e6d5b9f6a174a8d021d93db6b3497 Mon Sep 17 00:00:00 2001 From: MGS-sails Date: Tue, 7 Jan 2025 17:17:44 +0000 Subject: [PATCH] Refactored usage of BasePrivacyFilter. Reusable between models --- analyses/models.py | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/analyses/models.py b/analyses/models.py index edf0fe1..4e731dd 100644 --- a/analyses/models.py +++ b/analyses/models.py @@ -64,7 +64,7 @@ def lineage_to_path(lineage: str) -> str: return re.sub(r"[^a-zA-Z0-9._]", "", underscore_punctuated) -class BasePublicStudyManager: +class BasePrivacyFilterManager: """ Base mixin providing common privacy filtering methods for studies """ @@ -106,7 +106,7 @@ async def get_or_create_for_ena_study(self, ena_study_accession): return study -class PublicStudyManager(BasePublicStudyManager, StudyManager): +class PublicStudyManager(BasePrivacyFilterManager, StudyManager): """ A custom manager that filters out private studies by default. """ @@ -441,28 +441,8 @@ def get_queryset(self): return super().get_queryset() -class BasePublicAnalysisManager: - """ - Base mixin providing common privacy filtering methods - """ - - def get_queryset(self, include_private=False, private_only=False): - qs = super().get_queryset() - if private_only: - return qs.filter(is_private=True) - if not include_private: - return qs.filter(is_private=False) - return qs - - def private_only(self): - """ - Returns only private analyses - """ - return self.get_queryset(private_only=True) - - class PublicAnalysisManager( - BasePublicAnalysisManager, AnalysisManagerDeferringAnnotations + BasePrivacyFilterManager, AnalysisManagerDeferringAnnotations ): """ A custom manager that filters out private analyses by default. @@ -472,7 +452,7 @@ class PublicAnalysisManager( class PublicAnalysisManagerIncludingAnnotations( - BasePublicAnalysisManager, AnalysisManagerIncludingAnnotations + BasePrivacyFilterManager, AnalysisManagerIncludingAnnotations ): """ A custom manager that includes annotations but still filters out private analyses by default.