Skip to content

Commit

Permalink
Allow detecting location availability per postcode row
Browse files Browse the repository at this point in the history
If `--no-location` is not set we would try to detect a location for each row, and this would break if the location fields could not be coerced into floats.  Some datasets mix location and non-location postal codes and to import them all we have to filter the data and run the importer twice.

This change allows individual importers to implement `location_available_for_row` to say if the supplied row has location data or not.  The method is called on each row and will run the `--no-location` path if we can't extract location fields for that row.  If `--no-location` is set, we always run that path, regardless of the `location_available_for_row` value.
  • Loading branch information
h-lame committed Dec 15, 2015
1 parent b2d1d6d commit 74aa673
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mapit/management/commands/mapit_import_postal_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,11 @@ def pre_row(self, row, options):
def post_row(self, pc):
return True

def location_available_for_row(self, row):
return True

def handle_row(self, row, options):
if not options['location']:
if not options['location'] or not self.location_available_for_row(row):
return self.do_postcode()

if not options['coord-field-lon']:
Expand Down

0 comments on commit 74aa673

Please sign in to comment.