Skip to content

Commit

Permalink
Remove bugged get_facet_queryset method #4449
Browse files Browse the repository at this point in the history
  • Loading branch information
joemull committed Oct 9, 2024
1 parent 2ce25b8 commit 7d00f03
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 46 deletions.
23 changes: 6 additions & 17 deletions src/core/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
18 changes: 2 additions & 16 deletions src/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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 []
Expand Down Expand Up @@ -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
13 changes: 0 additions & 13 deletions src/journal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')),
Expand Down

0 comments on commit 7d00f03

Please sign in to comment.