Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
fix: Update addressee correspondence type field name in load_objects.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hepplerj committed May 13, 2024
1 parent 6860ac8 commit 9c54002
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions postcards/management/commands/load_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def load_data(self, file_path, sheet_name=None):

# Extract data from the row
addressee_correspodnence_type = (
row["addressee correspondence type"] or "Person"
row["addresse correspondence type"] or "Person"
).lower()
sender_correspondence_type = (
row["sender correspondence type"] or "Person"
Expand Down Expand Up @@ -220,16 +220,13 @@ def load_data(self, file_path, sheet_name=None):
else:
postmark_2_location = None

addressee = Person.objects.filter(
first_name=addressee_first_name,
last_name=addressee_last_name,
).first()
if not addressee:
self.stdout.write(
self.style.SUCCESS(
f"Creating addressee {addressee_first_name} {addressee_last_name}"
)
)
addressee = None
if addressee_first_name or addressee_last_name:
addressee = Person.objects.filter(
first_name=addressee_first_name,
last_name=addressee_last_name,
).first()
if not addressee and addressee_entity_name:
addressee = Person.objects.create(
entity_type=addressee_correspodnence_type,
title=addressee_title,
Expand All @@ -244,16 +241,22 @@ def load_data(self, file_path, sheet_name=None):
country=addressee_country,
).first(),
)
elif addressee:
addressee.entity_name = addressee_entity_name
addressee.save()

sender = Person.objects.filter(
first_name=sender_first_name, last_name=sender_last_name
).first()
if not sender:
self.stdout.write(
self.style.SUCCESS(
f"Creating sender {sender_first_name} {sender_last_name}"
f"Creating addressee {addressee_first_name} {addressee_last_name}"
)
)

sender = None
if sender_first_name or sender_last_name:
sender = Person.objects.filter(
first_name=sender_first_name, last_name=sender_last_name
).first()
if not sender and sender_entity_name:
sender = Person.objects.create(
entity_type=sender_correspondence_type,
title=sender_title,
Expand All @@ -268,6 +271,15 @@ def load_data(self, file_path, sheet_name=None):
country=sender_country,
).first(),
)
elif sender:
sender.entity_name = sender_entity_name
sender.save()

self.stdout.write(
self.style.SUCCESS(
f"Creating sender {sender_first_name} {sender_last_name}"
)
)

letter_type_mapping = {
"postcard": "Postcard",
Expand Down Expand Up @@ -301,14 +313,6 @@ def load_data(self, file_path, sheet_name=None):
name="Tim Gale"
) # Default to "Tim Gale"

# Before we write the data to the obj, we replace the None
# values with empty strings. This is done throughout all of the
# data. So, we find any instance where the value is None and
# replace it with an empty string.
# for key, value in row.items():
# if value is None:
# row[key] = ""

# Create or update Objects instance
obj, _ = Object.objects.get_or_create(
item_id=item_number,
Expand Down

0 comments on commit 9c54002

Please sign in to comment.