Skip to content

Commit

Permalink
Fix organization chamber match when bill sponsor is organization
Browse files Browse the repository at this point in the history
  • Loading branch information
jessemortenson committed Oct 10, 2024
1 parent 0210470 commit c8ed943
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions openstates/importers/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict:

org_name_prepositions = ["and", "at", "by", "for", "in", "on", "of", "the"]
name = spec.pop("name", None)
# if chamber is included in pseudo_person_id, we assume this is a committee
# and chamber is here to help us find its parent
chamber_classification = spec.pop("chamber", None)
if name:
# __icontains doesn't work for JSONField ArrayField
# so name follows "title" naming pattern
Expand All @@ -23,8 +26,14 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict:
name = re.sub(pattern, lambda match: match.group(0).lower(), name, flags=re.IGNORECASE)
name = name.replace(" & ", " and ")

return Q(**spec) & (
Q(name__iexact=name)
| Q(other_names__contains=[{"name": name}])
)
if chamber_classification:
return Q(**spec) & (
Q(name__iexact=name)
| Q(other_names__contains=[{"name": name}])
) & Q(parent__classification=chamber_classification)
else:
return Q(**spec) & (
Q(name__iexact=name)
| Q(other_names__contains=[{"name": name}])
)
return spec

0 comments on commit c8ed943

Please sign in to comment.