@@ -291,20 +291,15 @@ def spatial_data(self, obj, key):
291291 key = key )
292292 if context_identifier in self .context ['context_cache' ]:
293293 return self .context ['context_cache' ][context_identifier ]
294- data = (
295- self .context ['location_contexts' ].filter (
296- site_id = obj ['site_id' ],
297- group__key__icontains = key )
298- )
299- if data .exists ():
300- if data [0 ].value :
301- self .context ['context_cache' ][context_identifier ] = (
302- data [0 ].value
303- )
304- return data [0 ].value
305- self .context ['context_cache' ][context_identifier ] = (
306- '-'
307- )
294+ location_contexts = self .context ['location_contexts' ].filter (
295+ site_id = obj ['site_id' ]).order_by ('-fetch_time' )
296+ data = location_contexts .filter (group__name__iexact = key )
297+ if data .exists () and data .first ().value :
298+ self .context ['context_cache' ][context_identifier ] = (
299+ data .first ().value
300+ )
301+ return data .first ().value
302+ self .context ['context_cache' ][context_identifier ] = '-'
308303 return '-'
309304
310305 def get_source_reference (self , obj ):
@@ -406,37 +401,37 @@ def get_number_of_taxa(self, obj):
406401 return obj ['count' ]
407402
408403 def get_primary_catchment (self , obj ):
409- return self .spatial_data (obj , 'primary_catchment_area ' )
404+ return self .spatial_data (obj , 'primary catchment ' )
410405
411406 def get_secondary_catchment (self , obj ):
412- return self .spatial_data (obj , 'secondary_catchment_area ' )
407+ return self .spatial_data (obj , 'secondary catchment ' )
413408
414409 def get_tertiary_catchment (self , obj ):
415- return self .spatial_data (obj , 'tertiary_catchment_area ' )
410+ return self .spatial_data (obj , 'tertiary catchment ' )
416411
417412 def get_quaternary_catchment (self , obj ):
418- return self .spatial_data (obj , 'quaternary_catchment_area ' )
413+ return self .spatial_data (obj , 'quaternary catchment ' )
419414
420415 def get_water_management_area (self , obj ):
421- return self .spatial_data (obj , 'water_management_area ' )
416+ return self .spatial_data (obj , 'water management areas ' )
422417
423418 def get_sub_water_management_area (self , obj ):
424- return self .spatial_data (obj , 'sub_wmas ' )
419+ return self .spatial_data (obj , 'sub water management area ' )
425420
426421 def get_river_management_unit (self , obj ):
427- return self .spatial_data (obj , 'river_management_unit ' )
422+ return self .spatial_data (obj , 'river management unit ' )
428423
429424 def get_sa_ecoregion_level_1 (self , obj ):
430- return self .spatial_data (obj , 'eco_region_1 ' )
425+ return self .spatial_data (obj , 'SA Ecoregion Level 1 ' )
431426
432427 def get_sa_ecoregion_level_2 (self , obj ):
433- return self .spatial_data (obj , 'eco_region_2 ' )
428+ return self .spatial_data (obj , 'SA Ecoregion Level 2 ' )
434429
435430 def get_freshwater_ecoregion (self , obj ):
436- return self .spatial_data (obj , 'feow_hydrosheds ' )
431+ return self .spatial_data (obj , 'Freshwater Ecoregions of the World ' )
437432
438433 def get_province (self , obj ):
439- return self .spatial_data (obj , 'sa_provinces ' )
434+ return self .spatial_data (obj , 'SA Province and SADC boundaries ' )
440435
441436 def get_ASPT (self , obj ):
442437 return '{0:.2f}' .format (obj ['aspt' ])
0 commit comments