Skip to content

Commit

Permalink
adds supplement facets
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed Sep 5, 2024
1 parent e1fb8aa commit 9d761a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions peachjam/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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


Expand Down
13 changes: 10 additions & 3 deletions peachjam/views/gazette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"),
},
}


Expand Down

0 comments on commit 9d761a2

Please sign in to comment.