Skip to content

Commit

Permalink
bad cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Jan 27, 2024
1 parent d518fab commit 6d3b255
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
24 changes: 12 additions & 12 deletions camp_fin/management/commands/import_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def import_expenditures(self, f):
reader = csv.DictReader(f)

key_func = lambda record: (record["OrgID"], record["Report Name"])
sorted_records = sorted(reader, key=key_func)

sorted_records = sorted(
(row for row in reader if None not in key_func(row)), key=key_func
)

expenditures = []

Expand Down Expand Up @@ -296,20 +299,24 @@ def make_filing(self, record):
transaction_year = self.parse_date(transaction_date).year

try:
campaign = candidate.campaign_set.get(
election_season__year=transaction_year
campaign = models.Campaign.objects.get(
candidate=candidate, election_season__year=transaction_year
)
except models.Campaign.DoesNotExist:
self.stderr.write(
f"Could not find campaign for {candidate} in {transaction_year}"
)

campaign = None

if campaign and campaign.committee_name != record["Committee Name"]:
campaign.committee_name = record["Committee Name"]
campaign.save()

filing_kwargs = {"entity": candidate.entity, "campaign": campaign}
if campaign:
filing_kwargs = {"entity": candidate.entity, "campaign": campaign}
else:
filing_kwargs = {"entity": candidate.entity}

else:
pac = self.make_pac(record)
Expand Down Expand Up @@ -527,14 +534,7 @@ def _get_or_create_candidate(self, record):
last_name=record["Candidate Last Name"] or None,
suffix=record["Candidate Suffix"] or None,
full_name=full_name,
slug=slugify(
" ".join(
[
record["Candidate First Name"],
record["Candidate Last Name"],
]
)
),
slug=slugify(full_name),
entity=person,
)

Expand Down
22 changes: 10 additions & 12 deletions camp_fin/management/commands/import_office_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@ def handle(self, *args, **options):
" ".join(
[
candidate_name.get("GivenName", ""),
candidate_name.get("MiddleName", "")
or candidate_name.get("MiddleInitial", ""),
(
candidate_name.get("MiddleName", "")
or candidate_name.get("MiddleInitial", "")
or candidate_name.get("Nickname", "")
),
candidate_name.get("Surname", ""),
candidate_name.get("SuffixGenerational", "")
or candidate_name.get("SuffixOther", ""),
(
candidate_name.get("SuffixGenerational", "")
or candidate_name.get("SuffixOther", "")
),
]
),
).strip()
Expand Down Expand Up @@ -118,14 +123,7 @@ def handle(self, *args, **options):
or candidate_name.get("SuffixOther")
),
full_name=full_name,
slug=slugify(
" ".join(
[
candidate_name.get("GivenName", ""),
candidate_name.get("Surname", ""),
]
)
),
slug=slugify(full_name),
entity=person,
)

Expand Down

0 comments on commit 6d3b255

Please sign in to comment.