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

primary_sponsorships refactor #395

Merged
merged 1 commit into from
Jan 6, 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
8 changes: 3 additions & 5 deletions chicago/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.urls import reverse, reverse_lazy
from django.conf import settings

from .models import Person, Bill, Organization, Event
from .models import ChicagoPerson, Bill, Organization, Event
from .utils import to_datetime


Expand Down Expand Up @@ -107,7 +107,7 @@ class PersonDetailFeed(Feed):
NUM_RECENT_BILLS = 20

def get_object(self, request, slug):
o = Person.objects.get(slug=slug)
o = ChicagoPerson.objects.get(slug=slug)
return o

def title(self, obj):
Expand All @@ -132,9 +132,7 @@ def description(self, obj):
return "Recent sponsored bills from " + obj.name + "."

def items(self, person):
sponsored_bills = [s.bill for s in person.primary_sponsorships][:10]
recent_sponsored_bills = sponsored_bills[: self.NUM_RECENT_BILLS]
return recent_sponsored_bills
return person.primary_sponsorships[: self.NUM_RECENT_BILLS]


class CommitteeDetailEventsFeed(Feed):
Expand Down
10 changes: 10 additions & 0 deletions chicago/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ def years_in_office(self):
else:
return years

@property
def primary_sponsorships(self):
return (
ChicagoBill.objects.filter(
sponsorships__person=self, sponsorships__primary=True
)
.annotate(last_action=models.Max("actions__date"))
.order_by("-last_action")
)


class ChicagoPersonStatistic(models.Model):
person = models.OneToOneField(
Expand Down
9 changes: 1 addition & 8 deletions chicago/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,7 @@ 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"] = (
ChicagoBill.objects.filter(
sponsorships__person=person, sponsorships__primary=True
)
.annotate(last_action=Max("actions__date"))
.order_by("-last_action")[:10]
)
context["sponsored_legislation"] = person.primary_sponsorships[:10]
Copy link
Member Author

Choose a reason for hiding this comment

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

django interprets [:10] as limit 10 on the queryset so we can pass in our limit when we call this attribute


attendance = person.full_attendance
context["committee_count"] = len(person.current_memberships) - 1
Expand Down