Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add taxonomies to court listings #1936

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions peachjam/views/courts.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ def get_context_data(self, **kwargs):

context["doc_type"] = "Judgment"
context["page_title"] = self.page_title()
context["labels"].update({"judge": Judge.model_label_plural})
context["doc_table_show_jurisdiction"] = False

self.populate_years(context)
self.populate_facets(context)
self.show_facet_clear_all(context)

context["documents"] = self.group_documents(context["documents"])

return context

def populate_facets(self, context):
def add_facets(self, context):
context["facet_data"] = {}
if "judges" not in self.exclude_facets:
judges = list(
Expand All @@ -63,7 +59,7 @@ def populate_facets(self, context):
if judge
)
context["facet_data"]["judges"] = {
"label": _("Judges"),
"label": Judge.model_label_plural,
"type": "checkbox",
"options": judges,
"values": self.request.GET.getlist("judges"),
Expand Down Expand Up @@ -105,6 +101,24 @@ def populate_facets(self, context):
"values": self.request.GET.getlist("attorneys"),
}

if "taxonomy" not in self.exclude_facets:
taxonomies = list(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you sort these alphabetically at the last minute?

self.form.filter_queryset(
self.get_base_queryset(), exclude="taxonomies"
)
.filter(taxonomies__topic__isnull=False)
.order_by("taxonomies__topic__name")
.values_list("taxonomies__topic__name", flat=True)
.distinct()
)

context["facet_data"]["taxonomies"] = {
"label": _("Topics"),
"type": "checkbox",
"options": taxonomies,
"values": self.request.GET.getlist("taxonomies"),
}

if "alphabet" not in self.exclude_facets:
context["facet_data"]["alphabet"] = {
"label": _("Alphabet"),
Expand Down
5 changes: 2 additions & 3 deletions peachjam/views/generic_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def get_context_data(self, **kwargs):
self.add_facets(context)
self.show_facet_clear_all(context)
context["doc_count"] = context["paginator"].count
context["labels"] = {"author": Author.model_label}

return context

Expand Down Expand Up @@ -174,7 +173,7 @@ def add_facets(self, context):
taxonomies = list(
self.form.filter_queryset(self.get_base_queryset(), exclude="taxonomies")
.filter(taxonomies__topic__isnull=False)
.order_by()
.order_by("taxonomies__topic__name")
.values_list("taxonomies__topic__name", flat=True)
.distinct()
)
Expand All @@ -189,7 +188,7 @@ def add_facets(self, context):
"values": self.request.GET.getlist("years"),
},
"authors": {
"label": _("Authors"),
"label": Author.model_label_plural,
"type": "checkbox",
"options": authors,
"values": self.request.GET.getlist("authors"),
Expand Down
Loading