Skip to content

Commit

Permalink
adds nature filter to causelists
Browse files Browse the repository at this point in the history
  • Loading branch information
actlikewill committed Oct 17, 2024
1 parent c383f2e commit bb412ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 5 additions & 3 deletions peachjam/models/judgment.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,13 @@ class CauseList(CoreDocument):
judges = models.ManyToManyField(Judge, blank=True, verbose_name=_("judges"))

def assign_title(self):
court_name = self.court.name if self.court else ""
court_name = self.registry.name if self.registry else ""
if not self.registry:
court_name = self.court.name if self.court else ""
nature_name = self.nature.name if self.nature else ""
date_str = self.date.strftime("%Y-%m-%d") if self.date else ""
date_str = self.date.strftime("%d %B %Y")

self.title = f"{court_name} {nature_name} {date_str}"
self.title = f"{court_name} - {nature_name} - {date_str}"

def pre_save(self):
self.assign_title()
Expand Down
29 changes: 28 additions & 1 deletion peachjam/views/causelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
from django.views.generic import TemplateView

from peachjam.helpers import lowercase_alphabet
from peachjam.models import CauseList, Court, CourtClass, CourtRegistry, Judge, Taxonomy
from peachjam.models import (
CauseList,
Court,
CourtClass,
CourtRegistry,
DocumentNature,
Judge,
Taxonomy,
)
from peachjam.registry import registry
from peachjam.views import BaseDocumentDetailView, FilteredDocumentListView
from peachjam.views.courts import MonthMixin, RegistryMixin
Expand Down Expand Up @@ -84,6 +92,25 @@ def get_context_data(self, **kwargs):

def add_facets(self, context):
context["facet_data"] = {}

if "natures" not in self.exclude_facets:
natures = DocumentNature.objects.filter(
pk__in=self.form.filter_queryset(
self.get_base_queryset(), exclude="natures"
)
.order_by()
.values_list("nature_id", flat=True)
.distinct()
)
context["facet_data"]["natures"] = {
"label": _("Document nature"),
"type": "radio",
"options": sorted(
[(n.code, n.name) for n in natures], key=lambda x: x[1]
),
"values": self.request.GET.getlist("natures"),
}

if "judges" not in self.exclude_facets:
judges = list(
judge
Expand Down

0 comments on commit bb412ae

Please sign in to comment.