From 90281f6094f3b25f5895bbc9a9812087d31a981c Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Sat, 6 Jan 2024 09:02:14 -0500 Subject: [PATCH] fix facet selection --- chicago/views.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/chicago/views.py b/chicago/views.py index 7183929..d452507 100644 --- a/chicago/views.py +++ b/chicago/views.py @@ -182,13 +182,15 @@ def _get_selected_facets(self): for val in self.request.GET.getlist("selected_facets"): if val: - # e.g., bill_type_exact:ordinance -> bill_type, ordinance - k, v = val.split("_exact:", 1) + k, v = val.split(":", 1) + k = remove_suffix(k, "_exact") try: selected_facets[k].append(v) except KeyError: selected_facets[k] = [v] + print(selected_facets) + return selected_facets def _get_query_parameters(self): @@ -422,7 +424,14 @@ def get_context_data(self, **kwargs): ] = person.latest_council_membership.end_date_dt.strftime("%B %d, %Y") context["chair_positions"] = person.chair_role_memberships - context["sponsored_legislation"] = person.primary_sponsorships[:10] + + context["sponsored_legislation"] = ( + ChicagoBill.objects.filter( + sponsorships__person=person, sponsorships__primary=True + ) + .annotate(last_action=Max("actions__date")) + .order_by("-last_action")[:10] + ) attendance = person.full_attendance context["committee_count"] = len(person.current_memberships) - 1 @@ -701,3 +710,12 @@ def flush(request, flush_key): @xframe_options_exempt def pdfviewer(request): return render(request, "pdfviewer.html") + + +def remove_suffix(string, suffix): + + if string.endswith(suffix): + return string[: -len(suffix)] + + else: + return string