Skip to content

Commit

Permalink
Allow importing postcodes with no location
Browse files Browse the repository at this point in the history
Some rows in the ONSPD that have no location - those where the 12th column is a '9'.  The existing importers for ni and gb postcodes automatically ignore these, but it can be useful to include them for existence checks even if we can't give more geographical information about them.

We implement `location_available_for_row` to return `False` if the quality row is `'9'`, `True` otherwise.  This lets us import rows that have no location if we want to.  To keep the Code-Point Open import behaviour we provide an option `--allow-no-location-postcodes` to turn this on; without this option the importer will not import these rows.
  • Loading branch information
h-lame committed Dec 15, 2015
1 parent 32d772e commit 7f0f41e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mapit_gb/management/commands/mapit_UK_import_onspd.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,23 @@ class Command(Command):
default=False,
help='Set if you want to import terminated postcodes'
),
make_option(
'--allow-no-location-postcodes',
action='store_true',
dest='include-no-location',
default=False,
help='Set if you want to import postcodes without location info (quality: 9)'
),
)

def pre_row(self, row, options):
if row[4] and not options['include-terminated']:
return False # Terminated postcode
if row[11] == '9':
return False # PO Box etc.
if not(self.location_available_for_row(row) or options['include-no-location']):
return False # go no further unless we want codes with no location
if self.code[0:2] in ('GY', 'JE', 'IM', 'BT'):
return False # NI and channel islands handled by other commands
return True

def location_available_for_row(self, row):
return row[11] != '9' # PO Box etc.

0 comments on commit 7f0f41e

Please sign in to comment.