Skip to content

Commit

Permalink
Allow updating locationless postcodes
Browse files Browse the repository at this point in the history
- We needed to import a postcode apparently without a location, and
  the import was failing on this one specific postcode (HD7 9AS)
  because `pc.location` was blank. We've made this check more robust,
  and in the case where a postcode is blank, we've saved it anyway
  with the `location` data that comes from the file.
  • Loading branch information
issyl0 authored and dracos committed Apr 1, 2016
1 parent 6a33cc6 commit 92fd6c3
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions mapit/management/commands/mapit_import_postal_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,28 @@ def do_postcode(self, location=None, srid=None):
try:
pc = Postcode.objects.get(postcode=self.code)
if location:
curr_location = (pc.location[0], pc.location[1])
if settings.MAPIT_COUNTRY == 'GB':
if pc.postcode[0:2] == 'BT':
curr_location = pc.as_irish_grid()
else:
pc.location.transform(27700) # Postcode locations are stored as WGS84
curr_location = (pc.location[0], pc.location[1])
curr_location = tuple(map(round, curr_location))
elif srid != 4326:
pc.location.transform(srid) # Postcode locations are stored as WGS84
if pc.location:
curr_location = (pc.location[0], pc.location[1])
if curr_location[0] != location[0] or curr_location[1] != location[1]:
if settings.MAPIT_COUNTRY == 'GB':
if pc.postcode[0:2] == 'BT':
curr_location = pc.as_irish_grid()
else:
pc.location.transform(27700) # Postcode locations are stored as WGS84
curr_location = (pc.location[0], pc.location[1])
curr_location = tuple(map(round, curr_location))
elif srid != 4326:
pc.location.transform(srid) # Postcode locations are stored as WGS84
curr_location = (pc.location[0], pc.location[1])
if curr_location[0] != location[0] or curr_location[1] != location[1]:
pc.location = location
pc.save()
self.count['updated'] += 1
else:
self.count['unchanged'] += 1
else:
pc.location = location
pc.save()
self.count['updated'] += 1
else:
self.count['unchanged'] += 1
else:
self.count['unchanged'] += 1
except Postcode.DoesNotExist:
Expand Down

0 comments on commit 92fd6c3

Please sign in to comment.