Skip to content

Commit 08bc421

Browse files
committed
Fix assessment import bug
1 parent 5353881 commit 08bc421

File tree

3 files changed

+92
-53
lines changed

3 files changed

+92
-53
lines changed

dref/assessment_utils.py

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,15 @@ def f(r, c, i=0, as_list=False):
161161
).first()
162162
except District.DoesNotExist:
163163
pass
164+
if district is None:
165+
continue
164166
district_list.append(district)
165-
if paragraphs[6][0] == 'What happened, where and when?':
166-
description = paragraphs[7] or []
167-
data['event_description'] = ''.join(description) if description else None
167+
try:
168+
if paragraphs[6][0] == 'What happened, where and when?':
169+
description = paragraphs[7] or []
170+
data['event_description'] = ''.join(description) if description else None
171+
except IndexError:
172+
pass
168173

169174
# National Society Actions
170175
cells = get_table_cells(1)
@@ -220,33 +225,45 @@ def f(r, c, i=0, as_list=False):
220225
cells = get_table_cells(3)
221226
data['government_requested_assistance'] = parse_boolean(cells(0, 1))
222227

223-
national_authorities = cells(1, 1, as_list=True)
228+
national_authorities = cells(1, 2, as_list=True)
224229
data['national_authorities'] = ''.join(national_authorities) if national_authorities else None
225230

226-
un_and_other_actors = cells(2, 1, as_list=True)
231+
un_and_other_actors = cells(2, 2, as_list=True)
227232
data['un_or_other_actor'] = ''.join(un_and_other_actors) if un_and_other_actors else None
228233

229-
coordination_mechanism = cells(3, 1, as_list=True)
234+
coordination_mechanism = cells(4, 0, as_list=True)
230235
data['major_coordination_mechanism'] = ''.join(coordination_mechanism) if coordination_mechanism else None
231236

232237
# Operational Strategy
233-
if paragraphs[18][0] == 'Overall objective of the operation':
234-
operation_description = paragraphs[19] or []
235-
data['operation_objective'] = ''.join(operation_description) if operation_description else None
238+
try:
239+
if paragraphs[18][0] == 'Overall objective of the operation':
240+
operation_description = paragraphs[19] or []
241+
data['operation_objective'] = ''.join(operation_description) if operation_description else None
242+
except IndexError:
243+
pass
236244

237245
# targeting strategy
238-
if paragraphs[21][0] == 'Response strategy rationale':
239-
response_description = paragraphs[22] or []
240-
data['response_strategy'] = ''.join(response_description) if response_description else None
246+
try:
247+
if paragraphs[20][0] == 'Response strategy rationale':
248+
response_description = paragraphs[21] or []
249+
data['response_strategy'] = ''.join(response_description) if response_description else None
250+
except IndexError:
251+
pass
241252

242253
# Targeting Strategy
243-
if paragraphs[25][0] == 'Who will be targeted through this operation?':
244-
people_assisted_description = paragraphs[26] or []
245-
data['people_assisted'] = ''.join(people_assisted_description) if people_assisted_description else None
254+
try:
255+
if paragraphs[23][0] == 'Who will be targeted through this operation?':
256+
people_assisted_description = paragraphs[24] or []
257+
data['people_assisted'] = ''.join(people_assisted_description) if people_assisted_description else None
258+
except IndexError:
259+
pass
246260

247-
if paragraphs[27][0] == 'Explain the selection criteria for the targeted population':
248-
selection_criteria_description = paragraphs[28] or []
249-
data['selection_criteria'] = ''.join(selection_criteria_description) if selection_criteria_description else None
261+
try:
262+
if paragraphs[26][0] == 'Explain the selection criteria for the targeted population':
263+
selection_criteria_description = paragraphs[27] or []
264+
data['selection_criteria'] = ''.join(selection_criteria_description) if selection_criteria_description else None
265+
except IndexError:
266+
pass
250267

251268
# Targeting Population
252269
cells = get_table_cells(4)
@@ -311,13 +328,19 @@ def f(r, c, i=0, as_list=False):
311328
planned_intervention.append(planned)
312329

313330
# About Support Service
314-
if paragraphs[52][0] == 'How many volunteers and staff involved in the response? Briefly describe their role.':
315-
human_resource_description = paragraphs[53] or []
316-
data['human_resource'] = ''.join(human_resource_description) if human_resource_description else None
331+
try:
332+
if paragraphs[50][0] == 'How many volunteers and staff involved in the response? Briefly describe their role.':
333+
human_resource_description = paragraphs[51] or []
334+
data['human_resource'] = ''.join(human_resource_description) if human_resource_description else None
335+
except IndexError:
336+
pass
317337

318-
if paragraphs[54][0] == 'Will surge personnel be deployed? Please provide the role profile needed.':
319-
surge_personnel_deployed_description = paragraphs[55] or []
320-
data['surge_personnel_deployed'] = ''.join(surge_personnel_deployed_description) if surge_personnel_deployed_description else None
338+
try:
339+
if paragraphs[52][0] == 'Will surge personnel be deployed? Please provide the role profile needed.':
340+
surge_personnel_deployed_description = paragraphs[53] or []
341+
data['surge_personnel_deployed'] = ''.join(surge_personnel_deployed_description) if surge_personnel_deployed_description else None
342+
except IndexError:
343+
pass
321344

322345
try:
323346
national_society_contact = parse_contact_information(paragraphs[60] or [])
@@ -373,6 +396,7 @@ def f(r, c, i=0, as_list=False):
373396
dref = Dref.objects.create(**data)
374397
dref.planned_interventions.add(*planned_intervention)
375398
dref.national_society_actions.add(*national_societies)
399+
print(district_list)
376400
dref.risk_security.add(*mitigation_list)
377401
if len(district_list) > 0 and None not in district_list:
378402
dref.district.add(*district_list)

dref/imminent_utils.py

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -166,37 +166,50 @@ def f(r, c, d=0, as_list=False):
166166
).first()
167167
except District.DoesNotExist:
168168
pass
169+
if district is None:
170+
continue
169171
district_list.append(district)
170-
if paragraphs[6][0] == 'Approximate date of impact':
171-
paragraph6 = document.paragraphs[7]._element.xpath('.//w:t')
172-
event_desc = []
173-
if len(paragraph6) > 0:
174-
for desc in paragraph6:
175-
event_desc.append(desc.text)
176-
data['event_text'] = ''.join(event_desc) if event_desc else None
177-
178-
if paragraphs[8][0] == 'What is expected to happen?':
179-
paragraph8 = document.paragraphs[9]._element.xpath('.//w:t')
180-
event_description = []
181-
if len(paragraph8) > 0:
182-
for desc in paragraph8:
183-
event_description.append(desc.text)
184-
data['event_description'] = ''.join(event_description) if event_description else None
185-
186-
if paragraphs[11][0] == 'Why your National Society is acting now and what criteria is used to launch this operation.':
187-
paragraph11 = document.paragraphs[12]._element.xpath('.//w:t')
188-
anticipatory_actions_desc = []
189-
if len(paragraph11) > 0:
190-
for desc in paragraph11:
191-
anticipatory_actions_desc.append(desc.text)
172+
try:
173+
if paragraphs[6][0] == 'Approximate date of impact':
174+
paragraph6 = document.paragraphs[7]._element.xpath('.//w:t')
175+
event_desc = []
176+
if len(paragraph6) > 0:
177+
for desc in paragraph6:
178+
event_desc.append(desc.text)
179+
data['event_text'] = ''.join(event_desc) if event_desc else None
180+
except IndexError:
181+
pass
182+
try:
183+
if paragraphs[8][0] == 'What is expected to happen?':
184+
paragraph8 = document.paragraphs[9]._element.xpath('.//w:t')
185+
event_description = []
186+
if len(paragraph8) > 0:
187+
for desc in paragraph8:
188+
event_description.append(desc.text)
189+
data['event_description'] = ''.join(event_description) if event_description else None
190+
except IndexError:
191+
pass
192+
193+
try:
194+
if paragraphs[11][0] == 'Why your National Society is acting now and what criteria is used to launch this operation.':
195+
paragraph11 = document.paragraphs[12]._element.xpath('.//w:t')
196+
anticipatory_actions_desc = []
197+
if len(paragraph11) > 0:
198+
for desc in paragraph11:
199+
anticipatory_actions_desc.append(desc.text)
192200
data['anticipatory_actions'] = ''.join(anticipatory_actions_desc) if anticipatory_actions_desc else None
193-
if paragraphs[14][0] == 'Scope and scale':
194-
paragraph13 = document.paragraphs[15]._element.xpath('.//w:t')
195-
event_scope_description = []
196-
if len(paragraph13) > 0:
197-
for desc in paragraph13:
198-
event_scope_description.append(desc.text)
199-
data['event_scope'] = ''.join(event_scope_description) if event_scope_description else None
201+
except IndexError:
202+
pass
203+
try:
204+
if paragraphs[14][0] == 'Scope and scale':
205+
paragraph13 = document.paragraphs[15]._element.xpath('.//w:t')
206+
event_scope_description = []
207+
if len(paragraph13) > 0:
208+
for desc in paragraph13:
209+
event_scope_description.append(desc.text)
210+
data['event_scope'] = ''.join(event_scope_description) if event_scope_description else None
211+
except IndexError:
212+
pass
200213

201214
# Previous Operation
202215
# NOTE: I am not sure about the index 1 being used below - Bibek

dref/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ def f(r, c, i=0, as_list=False):
200200
).first()
201201
except District.DoesNotExist:
202202
pass
203+
if district is None:
204+
continue
203205
district_list.append(district)
204206

205207
try:

0 commit comments

Comments
 (0)