From 8a3ec878e7c7fae78f1f1013a68d20c81edc89e4 Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Sun, 30 Oct 2022 11:36:59 -0400 Subject: [PATCH 1/2] fixes for related bills and related actions --- pupa/importers/bills.py | 9 ++++++--- pupa/importers/vote_events.py | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pupa/importers/bills.py b/pupa/importers/bills.py index 32b715e5..fcf4221f 100644 --- a/pupa/importers/bills.py +++ b/pupa/importers/bills.py @@ -1,3 +1,5 @@ +from django.db.models import Q + from opencivicdata.legislative.models import (Bill, RelatedBill, BillAbstract, BillTitle, BillIdentifier, BillAction, BillActionRelatedEntity, BillSponsorship, BillSource, BillDocument, @@ -82,9 +84,10 @@ def postimport(self): bill__legislative_session__jurisdiction_id=self.jurisdiction_id, related_bill=None): candidates = list(Bill.objects.filter( - legislative_session__identifier=rb.legislative_session, - legislative_session__jurisdiction_id=self.jurisdiction_id, - identifier=rb.identifier) + Q(legislative_session__identifier=rb.legislative_session, + legislative_session__jurisdiction_id=self.jurisdiction_id), + Q(identifier=rb.identifier) | + Q(other_identifiers__identifier=rb.identifier)) ) if len(candidates) == 1: rb.related_bill = candidates[0] diff --git a/pupa/importers/vote_events.py b/pupa/importers/vote_events.py index 614508ee..707f7062 100644 --- a/pupa/importers/vote_events.py +++ b/pupa/importers/vote_events.py @@ -84,8 +84,7 @@ def prepare_for_db(self, data): organization_id=data['organization_id'], ) # seen_action_ids is for ones being added in this import - # action.vote is already set if action was set on prior import - if action.id in self.seen_action_ids or hasattr(action, 'vote'): + if action.id in self.seen_action_ids: self.warning('can not match two VoteEvents to %s: %s', action.id, bill_action) else: From be77910b68c96275c670d905e231ddd41a5a082f Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Sun, 23 Jul 2023 09:07:08 -0400 Subject: [PATCH 2/2] black --- pupa/importers/bills.py | 19 ++++++++++++------- pupa/importers/vote_events.py | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pupa/importers/bills.py b/pupa/importers/bills.py index bfeb964a..5cc1665f 100644 --- a/pupa/importers/bills.py +++ b/pupa/importers/bills.py @@ -111,13 +111,18 @@ def postimport(self): # go through all RelatedBill objs that are attached to a bill in this # jurisdiction and are currently unresolved for rb in RelatedBill.objects.filter( - bill__legislative_session__jurisdiction_id=self.jurisdiction_id, - related_bill=None): - candidates = list(Bill.objects.filter( - Q(legislative_session__identifier=rb.legislative_session, - legislative_session__jurisdiction_id=self.jurisdiction_id), - Q(identifier=rb.identifier) | - Q(other_identifiers__identifier=rb.identifier)) + bill__legislative_session__jurisdiction_id=self.jurisdiction_id, + related_bill=None, + ): + candidates = list( + Bill.objects.filter( + Q( + legislative_session__identifier=rb.legislative_session, + legislative_session__jurisdiction_id=self.jurisdiction_id, + ), + Q(identifier=rb.identifier) + | Q(other_identifiers__identifier=rb.identifier), + ) ) if len(candidates) == 1: rb.related_bill = candidates[0] diff --git a/pupa/importers/vote_events.py b/pupa/importers/vote_events.py index ebefabfb..be144a09 100644 --- a/pupa/importers/vote_events.py +++ b/pupa/importers/vote_events.py @@ -99,8 +99,9 @@ def prepare_for_db(self, data): organization_id=data["organization_id"], ) if action.id in self.seen_action_ids: - self.warning('can not match two VoteEvents to %s: %s', - action.id, bill_action) + self.warning( + "can not match two VoteEvents to %s: %s", action.id, bill_action + ) else: data["bill_action_id"] = action.id self.seen_action_ids.add(action.id)