Skip to content

Commit

Permalink
catch status errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ashimali committed Nov 25, 2024
1 parent 3884fd1 commit 8b4d7c0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions application/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def populate_object(form, obj):
del form.lds_published_date_day

if hasattr(form, "status") and form.status.data:
status_name = form.status.data.split(".")[1]
obj.status = Status[status_name]
obj.status = string_to_status(form.status.data)
del form.status

form.populate_obj(obj)
Expand Down Expand Up @@ -208,3 +207,14 @@ def to_url(self, event_category):
event_category = event_category.name.lower()
event_category = event_category.replace("_", "-")
return event_category


def string_to_status(status_string):
try:
enum_name = status_string.split(".")[
1
] # Gets "EXPORTED" from "Status.EXPORTED"
return Status[enum_name]
except (IndexError, KeyError):
print(f"Invalid status string: {status_string}")
return None

0 comments on commit 8b4d7c0

Please sign in to comment.