@@ -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 )
0 commit comments