From 698e75cca4d72691222df2a42057332db9a49bb6 Mon Sep 17 00:00:00 2001
From: Derek Eder {%if event.status == 'cancelled'%}CANCELLED: {% endif %}{{event.name}}
{{event.location}}
-
Order | +Description | +ID | +Sponsor(s) | +||
---|---|---|---|---|---|
{{ forloop.counter }} | +{{agenda_item.description}} | + {% if agenda_item.related_entities.first.bill.councilmatic_bill %} ++ + {{ agenda_item.related_entities.first.bill.councilmatic_bill.friendly_name }} + + | ++ {% for s in agenda_item.related_entities.first.bill.councilmatic_bill.sponsorships.all %} + {{ s.person.link_html | safe }}{% if not forloop.last %},{% endif %} + {% endfor %} + | + {% else %} ++ | {% endif %} - {{agenda_item.description}} - - {% endif %} + {% endif %} + |
{{ forloop.counter }} | diff --git a/chicago/templates/legislation.html b/chicago/templates/legislation.html index d44ca92..73e56ce 100644 --- a/chicago/templates/legislation.html +++ b/chicago/templates/legislation.html @@ -30,7 +30,7 @@|||||||||||||||
- {% if legislation.sponsorships.all|length > 1 %}
- Sponsors ({{legislation.sponsorships.all|length}})
+ {% if legislation.sponsors.all|length > 1 %}
+ Sponsors ({{legislation.sponsors.all|length}})
{% else %}
Sponsor
{% endif %}
@@ -63,36 +63,36 @@ Sponsors | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
-
+
|
- {{ s.person.link_html | safe }} Primary Sponsor + {{ s.person.name }}Primary Sponsor | - {{s.person.latest_council_membership.post.label}} + {{s.person.council_posts.0.post.label}} | |||||||||||||
-
+
|
- {{ s.person.link_html | safe }} + {{ s.person.name }} | - {{s.person.latest_council_membership.post.label}} + {{s.person.council_posts.0.post.label}} |
{{action.date}}
@@ -215,7 +215,7 @@ Upcoming {{ CITY_VOCAB.EVENTS }}{% for event in legislation.unique_related_upcoming_events %}- {{event.start_time | date:'M d, Y' }} - {{event.link_html | safe}} + {{event.start_time | date:'M d, Y' }} - {{ event.name }} {% endfor %} @@ -278,7 +278,7 @@Legislation not found"sourceOrganization": "{{ CITY_COUNCIL_NAME }}", "name": "{{ legislation.friendly_name }}", "alternateName": ["{{ legislation.identifier }}", "{{ legislation.identifier.split|join:'' }}"], - {% if actions %}"datePublished": "{{actions.0.date|date:'Y-m-d'}}", {% endif %} + {% if legislation.actions %}"datePublished": "{{legislation.actions.0.date|date:'Y-m-d'}}", {% endif %} "description": "{{ legislation.description }}", "text": "{% firstof legislation.full_text legislation.ocr_full_text %}" } diff --git a/chicago/views.py b/chicago/views.py index 62b3962..e2bf656 100644 --- a/chicago/views.py +++ b/chicago/views.py @@ -4,15 +4,13 @@ from urllib.parse import urlencode import pytz -from councilmatic_core.models import Organization, Post +from councilmatic_core.models import BillAction, Organization, Post from councilmatic_core.views import ( AboutView, - BillDetailView, CommitteeDetailView, CommitteesView, CouncilmaticSearchForm, CouncilMembersView, - EventDetailView, EventsView, IndexView, PersonDetailView, @@ -24,9 +22,16 @@ from django.http import Http404, HttpResponsePermanentRedirect from django.urls import reverse from django.utils import timezone -from django.views.generic import ListView, DetailView +from django.views.generic import DetailView, ListView from haystack.generic_views import FacetedSearchView -from opencivicdata.legislative.models import LegislativeSession, PersonVote +from opencivicdata.core.models import Membership +from opencivicdata.legislative.models import ( + BillSponsorship, + EventAgendaItem, + EventRelatedEntity, + LegislativeSession, + PersonVote, +) from chicago.models import ChicagoBill, ChicagoEvent, ChicagoOrganization, ChicagoPerson @@ -227,13 +232,11 @@ def get(self, request, *args, **kwargs): except self.model.DoesNotExist: raise Http404 - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - - bill = self.object + def get_queryset(self): - context["actions"] = ( - bill.actions.order_by("-order") + # Getting a handle on vote details + actions_qs = ( + BillAction.objects.order_by("-order") .select_related("organization__councilmatic_organization") .select_related("vote") .prefetch_related( @@ -246,6 +249,37 @@ def get_context_data(self, **kwargs): ) ) + # Getting a handle on sponsors and council posts + sponsorships_qs = ( + BillSponsorship.objects.filter(person_id__isnull=False) + .select_related("person__councilmatic_person") + .prefetch_related( + Prefetch( + "person__memberships", + queryset=Membership.objects.filter( + organization__name=settings.OCD_CITY_COUNCIL_NAME + ) + .order_by("-start_date", "-end_date") + .select_related("post"), + to_attr="council_posts", + ) + ) + ) + + return ( + super() + .get_queryset() + .prefetch_related(Prefetch("actions", queryset=actions_qs)) + .prefetch_related( + Prefetch("sponsorships", queryset=sponsorships_qs, to_attr="sponsors") + ) + ) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + bill = self.object + seo = {} seo.update(settings.SITE_META) seo["site_desc"] = bill.listing_description @@ -490,12 +524,13 @@ def get_context_data(self, **kwargs): return context -class ChicagoEventDetailView(EventDetailView): +class ChicagoEventDetailView(DetailView): model = ChicagoEvent template_name = "event.html" + context_object_name = "event" def get_context_data(self, **kwargs): - context = super(EventDetailView, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) event = context["event"] # getting expected attendees and actual attendees @@ -540,3 +575,28 @@ def get_context_data(self, **kwargs): context["seo"] = seo return context + + def get_queryset(self): + + sponsors_qs = BillSponsorship.objects.filter( + person_id__isnull=False + ).select_related("person__councilmatic_person") + + related_bill_qs = ( + EventRelatedEntity.objects.filter(entity_type="bill") + .select_related("bill__councilmatic_bill") + .prefetch_related( + Prefetch("bill__sponsorships", queryset=sponsors_qs, to_attr="sponsors") + ) + ) + + agenda_items_qs = EventAgendaItem.objects.order_by("order").prefetch_related( + Prefetch("related_entities", queryset=related_bill_qs, to_attr="bills") + ) + + return ( + super() + .get_queryset() + .prefetch_related(Prefetch("agenda", queryset=agenda_items_qs)) + .prefetch_related("documents") + ) From eb6a8ffb0eff19ac5f1d4fa18e853210700c4cf5 Mon Sep 17 00:00:00 2001 From: Forest Gregg | ||||||
- {% if legislation.sponsors.all|length > 1 %}
- Sponsors ({{legislation.sponsors.all|length}})
+ {% if sponsors|length > 1 %}
+ Sponsors ({{sponsors|length}})
{% else %}
Sponsor
{% endif %}
@@ -63,7 +66,7 @@ Sponsors | ||||||
---|---|---|---|---|---|---|
@@ -80,7 +83,7 @@ Sponsors | ||||||
@@ -102,6 +105,7 @@ Sponsors{% endif %} + {% endwith %} {% if legislation.actions %}Historydiff --git a/chicago/views.py b/chicago/views.py index e2bf656..59fa483 100644 --- a/chicago/views.py +++ b/chicago/views.py @@ -18,7 +18,7 @@ from dateutil import parser from dateutil.relativedelta import relativedelta from django.conf import settings -from django.db.models import Max, Min, Prefetch +from django.db.models import Max, Min, Prefetch, Subquery from django.http import Http404, HttpResponsePermanentRedirect from django.urls import reverse from django.utils import timezone @@ -247,17 +247,37 @@ def get_queryset(self): ), ) ) + .prefetch_related("vote__counts") ) - # Getting a handle on sponsors and council posts - sponsorships_qs = ( - BillSponsorship.objects.filter(person_id__isnull=False) + return ( + super() + .get_queryset() + .prefetch_related(Prefetch("actions", queryset=actions_qs)) + ) + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + bill = self.object + + # we have to do the sponsors here, instead of in get_queryset + # because we need a handle on the actual bill object in order + # to get the council post as of the first action on the bill + first_action_date_subquery = ( + BillAction.objects.filter(bill_id=bill).order_by("order").values("date")[:1] + ) + + sponsors = ( + bill.sponsorships.filter(person_id__isnull=False) .select_related("person__councilmatic_person") .prefetch_related( Prefetch( "person__memberships", queryset=Membership.objects.filter( - organization__name=settings.OCD_CITY_COUNCIL_NAME + organization__name=settings.OCD_CITY_COUNCIL_NAME, + start_date__lte=Subquery(first_action_date_subquery), + end_date__gte=Subquery(first_action_date_subquery), ) .order_by("-start_date", "-end_date") .select_related("post"), @@ -266,19 +286,7 @@ def get_queryset(self): ) ) - return ( - super() - .get_queryset() - .prefetch_related(Prefetch("actions", queryset=actions_qs)) - .prefetch_related( - Prefetch("sponsorships", queryset=sponsorships_qs, to_attr="sponsors") - ) - ) - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - - bill = self.object + context["sponsors_qs"] = sponsors seo = {} seo.update(settings.SITE_META) From ebf7d480baac0550fb777c9a4563c42a261e36b1 Mon Sep 17 00:00:00 2001 From: Derek Eder{%if event.status == 'cancelled'%}CANCELLED: {% endif %}{{event.name}}{% endif %}-
-
+
+
{% if event.agenda.all %}
-
- Agenda+Agenda: {{event.agenda.all|length}} items
Attachments-
- {% for document in event.documents.all %}
- {{document.note}}
-
- {{ event|get_legistar_link|safe }}
-
-
{% if event.status == 'passed' %}
{% if attendance_taken %}
- Attendance: {{attendance_present}} Present, {{attendance_absent}} Absent+Alder Attendance: {{attendance_present}} Present, {{attendance_absent}} Absent
|