From f20bbb70b9ab2d913b8ba9b168d94fb0d29d7d0c Mon Sep 17 00:00:00 2001 From: Asgef Date: Thu, 13 Jun 2024 17:56:44 +0300 Subject: [PATCH] [#429] Fix labels search Link get_queruset() method logic to ContributionLabelsMixin --- contributors/views/generic_list_views/issues.py | 6 ++++-- contributors/views/mixins.py | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/contributors/views/generic_list_views/issues.py b/contributors/views/generic_list_views/issues.py index aa79863..540f2b5 100644 --- a/contributors/views/generic_list_views/issues.py +++ b/contributors/views/generic_list_views/issues.py @@ -38,8 +38,8 @@ class ListView( queryset=ContributionLabel.objects.all(), ) - def get_queryset(self): - """Add queryset.""" + def get_queryset(self): # noqa: WPS615 + """Get the initial queryset and apply all filters.""" queryset = ( Contribution.objects.filter(type='iss'). select_related('repository', 'contributor', 'info'). @@ -48,6 +48,8 @@ def get_queryset(self): self.contributionlabel_prefetch, ).distinct() ) + self.queryset = queryset + queryset = super().get_queryset() self.filterset = self.filterset_class( self.request.GET, queryset=queryset, diff --git a/contributors/views/mixins.py b/contributors/views/mixins.py index 4cdfbc6..31eec4b 100644 --- a/contributors/views/mixins.py +++ b/contributors/views/mixins.py @@ -170,15 +170,16 @@ def get_queryset(self): # noqa: WPS615 class ContributionLabelsMixin(object): """A mixin for labels.""" - def get_queryset(self): # noqa: WPS615 - """Get a dataset.""" + def get_queryset(self): + """Get a dataset and apply label filters if any.""" + queryset = super().get_queryset() labels_param = self.request.GET.get('contribution_labels') if labels_param: labels_param = labels_param.split('.') - self.queryset = self.queryset.filter( + queryset = queryset.filter( labels__name__lower__in=labels_param, - ) - return super().get_queryset() + ).distinct() + return queryset class ContributorTotalStatMixin(object):