Skip to content

Commit

Permalink
Return value for get_all_session()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexobaseki committed Oct 18, 2024
1 parent fa3452e commit d9de13b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions openstates/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ def __init__(self, jurisdiction_id: str, do_postimport=True) -> None:
if settings.IMPORT_TRANSFORMERS.get(self._type):
self.cached_transformers = settings.IMPORT_TRANSFORMERS[self._type]

def get_all_sessions(self) -> None:
def get_all_sessions(self) -> typing.List[LegislativeSession]:
if not self.all_sessions_cache:
self.all_sessions_cache = LegislativeSession.objects.filter(
jurisdiction_id=self.jurisdiction_id
).order_by("-start_date")
return self.all_sessions_cache

def get_session(self, identifier: str) -> LegislativeSession:
if identifier not in self.session_cache:
Expand Down Expand Up @@ -173,7 +174,7 @@ def resolve_bill(self, bill_id: str, *, date: str) -> typing.Optional[_ID]:
bill_transform_func = settings.IMPORT_TRANSFORMERS.get("bill", {}).get(
"identifier", None
)
self.get_all_sessions()
all_sessions = self.get_all_sessions()
if bill_transform_func:
bill_id = bill_transform_func(bill_id)

Expand All @@ -182,15 +183,15 @@ def resolve_bill(self, bill_id: str, *, date: str) -> typing.Optional[_ID]:
date = datetime.fromisoformat(date).strftime("%Y-%m-%d")
session_ids = [
session.id
for session in self.all_sessions_cache
for session in all_sessions
if session.start_date <= date
and (session.end_date >= date or not session.end_date)
]

if len(session_ids) == 1:
session_id = session_ids.pop()
else:
session_id = self.all_sessions_cache[0].id if self.all_sessions_cache else None
session_id = all_sessions[0].id if all_sessions else None

objects = Bill.objects.filter(
legislative_session__id=session_id,
Expand Down

0 comments on commit d9de13b

Please sign in to comment.