From bd17e353bbe8b9bc4d576f5f7c6e6b716e18a69f Mon Sep 17 00:00:00 2001 From: George Helman Date: Sat, 16 Nov 2024 15:04:26 -0500 Subject: [PATCH 1/2] #515 Fix combining batches error reported on 10/28 --- dear_petition/petition/resources.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dear_petition/petition/resources.py b/dear_petition/petition/resources.py index 30fc4ddb..367dfde2 100644 --- a/dear_petition/petition/resources.py +++ b/dear_petition/petition/resources.py @@ -283,25 +283,29 @@ class RecordResource(MultiModelResource): def dehydrate_jurisdiction(self, record): jurisdiction = getattr(record, "jurisdiction") - return constants.JURISDICTION_MAP[jurisdiction] + return constants.JURISDICTION_MAP.get(jurisdiction, constants.NOT_AVAILABLE) def hydrate_jurisdiction(self, field, data): attribute = field.attribute + hydrated_value = constants.NOT_AVAILABLE for k, v in constants.JURISDICTION_MAP.items(): if v == data[attribute]: - data[attribute] = k + hydrated_value = k break - + data[attribute] = hydrated_value return data def dehydrate_sex(self, record): sex = getattr(record, "sex") - return constants.SEX_CHOICES[sex] + try: + sex_value = constants.SEX_CHOICES[sex] + except: + sex_value = constants.NOT_AVAILABLE + return sex_value def hydrate_sex(self, field, data): attribute = field.attribute - data[attribute] = constants.SEX_MAP[data[attribute]] - + data[attribute] = constants.SEX_MAP.get(data[attribute], constants.NOT_AVAILABLE) return data def get_export_fields(self): From 8a66edb155ce76e80c668c6795bc5deff5e43264 Mon Sep 17 00:00:00 2001 From: George Helman Date: Tue, 26 Nov 2024 18:04:57 -0500 Subject: [PATCH 2/2] Make except clause more specific --- dear_petition/petition/resources.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dear_petition/petition/resources.py b/dear_petition/petition/resources.py index 367dfde2..f86a8429 100644 --- a/dear_petition/petition/resources.py +++ b/dear_petition/petition/resources.py @@ -299,7 +299,7 @@ def dehydrate_sex(self, record): sex = getattr(record, "sex") try: sex_value = constants.SEX_CHOICES[sex] - except: + except KeyError: sex_value = constants.NOT_AVAILABLE return sex_value