From 9d761a21b09a177ac2f5fe997a56a94515836092 Mon Sep 17 00:00:00 2001 From: actlikewill Date: Thu, 5 Sep 2024 20:06:37 +0300 Subject: [PATCH] adds supplement facets --- peachjam/forms.py | 5 +++++ peachjam/views/gazette.py | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/peachjam/forms.py b/peachjam/forms.py index 2ae63cede..681966ca0 100644 --- a/peachjam/forms.py +++ b/peachjam/forms.py @@ -222,11 +222,13 @@ def order_queryset(self, queryset, exclude=None): class GazetteFilterForm(BaseDocumentFilterForm): sub_publications = PermissiveTypedListField(coerce=remove_nulls, required=False) special = PermissiveTypedListField(coerce=remove_nulls, required=False) + supplement = forms.BooleanField(required=False) def filter_queryset(self, queryset, exclude=None, filter_q=False): queryset = super().filter_queryset(queryset, exclude, filter_q) sub_publications = self.cleaned_data.get("sub_publications", []) special = self.cleaned_data.get("special", []) + supplement = self.cleaned_data.get("supplement", False) if sub_publications and exclude != "sub_publications": queryset = queryset.filter(sub_publication__in=sub_publications) @@ -239,6 +241,9 @@ def filter_queryset(self, queryset, exclude=None, filter_q=False): special_qs |= Q(special=False) queryset = queryset.filter(special_qs) + if supplement and exclude != "supplement": + queryset = queryset.filter(supplement=True) + return queryset diff --git a/peachjam/views/gazette.py b/peachjam/views/gazette.py index 6de7872c6..47695e35a 100644 --- a/peachjam/views/gazette.py +++ b/peachjam/views/gazette.py @@ -4,7 +4,8 @@ from django.db.models.functions import ExtractMonth, ExtractYear from django.urls import reverse from django.utils.dates import MONTHS -from django.utils.translation import gettext_lazy as _ +from django.utils.translation import gettext as _ +from django.utils.translation import gettext_lazy as __ from django.views.generic import TemplateView from peachjam.forms import GazetteFilterForm @@ -123,8 +124,8 @@ class GazetteYearView(YearMixin, FilteredDocumentListView): locality = None group_by_date = "month-year" special_facet_options = [ - ("special", _("Special Issue")), - ("not_special", _("Regular Issue")), + ("special", __("Special Issue")), + ("not_special", __("Regular Issue")), ] def get_form(self): @@ -199,6 +200,12 @@ def add_facets(self, context): "options": self.special_facet_options, "values": self.request.GET.getlist("special"), }, + "supplement": { + "label": _("Supplement"), + "type": "checkbox", + "options": [("true", _("Supplement"))], + "values": self.request.GET.getlist("supplement"), + }, }