From 7d00f0304e1e7ab8d6dbfadf57eddb31e3374208 Mon Sep 17 00:00:00 2001 From: Joseph Muller Date: Wed, 9 Oct 2024 16:49:29 +0100 Subject: [PATCH] Remove bugged get_facet_queryset method #4449 --- src/core/forms/forms.py | 23 ++++++----------------- src/core/views.py | 18 ++---------------- src/journal/views.py | 13 ------------- 3 files changed, 8 insertions(+), 46 deletions(-) diff --git a/src/core/forms/forms.py b/src/core/forms/forms.py index 89d7df0e9..1c9b44e4a 100755 --- a/src/core/forms/forms.py +++ b/src/core/forms/forms.py @@ -589,18 +589,14 @@ def save(self, commit=True): class CBVFacetForm(forms.Form): def __init__(self, *args, **kwargs): - # This form populates the facets that users can filter results on - # If you pass a separate facet_queryset into kwargs, the form is - # the same regardless of how the result queryset changes - # To have the facets dynamically contract based on the result queryset, - # do not pass anything for facet_queryset into kwargs. + # This form populates the facets that users can filter results on. + # The facets dynamically change based on the queryset of results, + # so users only see filter options that will have an effect on the + # current results. self.id = 'facet_form' self.queryset = kwargs.pop('queryset') self.facets = kwargs.pop('facets') - self.facet_queryset = kwargs.pop('facet_queryset', None) - if not self.facet_queryset: - self.facet_queryset = self.queryset self.fields = {} super().__init__(*args, **kwargs) @@ -611,10 +607,7 @@ def __init__(self, *args, **kwargs): # Note: This retrieval is written to work even for sqlite3. # It might be rewritten differently if sqlite3 support isn't needed. - if self.facet_queryset: - column = self.facet_queryset.values_list(facet_key, flat=True) - else: - column = self.queryset.values_list(facet_key, flat=True) + column = self.queryset.values_list(facet_key, flat=True) values_list = list(filter(bool, column)) choice_queryset = facet['model'].objects.filter(pk__in=values_list) @@ -642,14 +635,10 @@ def __init__(self, *args, **kwargs): # Note: This retrieval is written to work even for sqlite3. # It might be rewritten differently if sqlite3 support isn't needed. - if self.facet_queryset: - queryset = self.facet_queryset - else: - queryset = self.queryset column = [] values_list = [] lookup_parts = facet_key.split('.') - for obj in queryset: + for obj in self.queryset: for part in lookup_parts: if obj: try: diff --git a/src/core/views.py b/src/core/views.py index c5ad018bc..49f74e260 100755 --- a/src/core/views.py +++ b/src/core/views.py @@ -2487,7 +2487,6 @@ def get_context_data(self, **kwargs): context['facet_form'] = forms.CBVFacetForm( queryset=queryset, - facet_queryset=self.get_facet_queryset(), facets=facets, initial=initial, ) @@ -2580,18 +2579,8 @@ def get_facets(self): return self.filter_facets_if_journal(facets) def get_facet_queryset(self): - # The default behavior is for the facets to stay the same - # when a filter is chosen. - # To make them change dynamically, return None - # instead of a separate facet. - # return None - - journal_query = self.get_journal_filter_query() - queryset = super().get_queryset().filter(journal_query) - facets = self.get_facets() - for facet in facets.values(): - queryset = queryset.annotate(**facet.get('annotations', {})) - return queryset.order_by() + # This method is deprecated. + return None def get_actions(self): return [] @@ -2780,6 +2769,3 @@ def post(self, request, *args, **kwargs): messages.success(request, message) return super().post(request, *args, **kwargs) - - def get_facet_queryset(self): - return None diff --git a/src/journal/views.py b/src/journal/views.py index 69e518d15..da3e6b163 100755 --- a/src/journal/views.py +++ b/src/journal/views.py @@ -2820,12 +2820,6 @@ def get_queryset(self, params_querydict=None): stage=submission_models.STAGE_UNSUBMITTED ) - def get_facet_queryset(self, **kwargs): - queryset = super().get_facet_queryset(**kwargs) - return queryset.exclude( - stage=submission_models.STAGE_UNSUBMITTED - ) - @method_decorator(has_journal, name='dispatch') @method_decorator(decorators.frontend_enabled, name='dispatch') @@ -2863,13 +2857,6 @@ def get_facets(self): } return self.filter_facets_if_journal(facets) - def get_facet_queryset(self): - queryset = super().get_facet_queryset() - return queryset.filter( - date_published__lte=timezone.now(), - stage=submission_models.STAGE_PUBLISHED, - ) - def get_order_by_choices(self): return [ ('-date_published', _('Newest')),