Skip to content

Commit

Permalink
Merge pull request #148 from openstates/fix-organization-sponsor-cham…
Browse files Browse the repository at this point in the history
…ber-match

Fix organization chamber match when bill sponsor is organization
  • Loading branch information
jessemortenson authored Oct 10, 2024
2 parents 0210470 + 05ed5f2 commit 251a29c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 6.20.7 - Oct 10, 2024

* Fix matching committee organizations when chamber is specified for an organizational bill sponsor

## 6.20.6 - Sept 18, 2024

* Add steps to publish lightweight openstates-metadata
Expand Down
23 changes: 17 additions & 6 deletions openstates/importers/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,27 @@ 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
name = name.title()
pattern = '(' + '|'.join(org_name_prepositions) + ')'
name = re.sub(pattern, lambda match: match.group(0).lower(), name, flags=re.IGNORECASE)
pattern = "(" + "|".join(org_name_prepositions) + ")"
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "openstates"
version = "6.20.6"
version = "6.20.7"
description = "core infrastructure for the openstates project"
authors = ["James Turk <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 251a29c

Please sign in to comment.