Skip to content

Commit e6a7b38

Browse files
committed
Fix project import error message
1 parent 1a40a49 commit e6a7b38

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

deployments/forms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def _parse_integer(integer):
227227
disaster_type_id = disaster_types[disaster_type_name.lower()] if disaster_type_name else None
228228

229229
row_errors = {}
230+
project_country = Country.objects.filter(name__iexact=country_name).first()
230231
project_districts = []
231232
if district_names:
232233
project_districts = list(District.objects.filter(
@@ -240,12 +241,11 @@ def _parse_integer(integer):
240241
).all())
241242
# Check if all district_names is available in db
242243
if len(project_districts) == len(district_names):
243-
project_country = project_districts[0].country
244+
if project_country is None: # in case of we did not find a proper country name, trying to know it:
245+
project_country = project_districts[0].country
244246
else:
245-
# District list can be empty. If not empty, we get country name from the first one.
246-
project_country = None
247-
else:
248-
project_country = Country.objects.filter(name__iexact=country_name).first()
247+
# but it can not happen that some of the given district-names cannot be found:
248+
row_errors['project_districts'] = [f'Some given district_names are not available. "{district_names}"']
249249

250250
# A validation error will be raised. This is just a custom message
251251
if project_country is None:

0 commit comments

Comments
 (0)