Skip to content

Commit

Permalink
Make adding gss codes to ni areas work for real data
Browse files Browse the repository at this point in the history
We incorporate the feedback from mysociety about running the `mapit_UK_add_gss_codes_to_ni_areas` command against their real data.  Because we're doing name matches we need to change our naive `names_name__iexact` match and sanitize the data a bit.
  • Loading branch information
h-lame committed Dec 18, 2015
1 parent 99847c4 commit f4e27f3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions mapit_gb/management/commands/mapit_UK_add_gss_codes_to_ni_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,29 @@ def update_lgws_for_lge(self, wards, lgd, lge):
' LGD "%s" to add GSS "%s" to') % (ward_name, lge.name, lgd.name, ward_gss_code)

def fetch_and_update_area(self, area_source, area_type, area_name, area_gss_code):
area_name = area_name.replace('St. ', 'St ')
try:
area = area_source.get(
country=self.country, type__code=area_type,
names__name__iexact=area_name,
name__iexact=area_name,
generation_low__lte=self.current_generation,
generation_high__gte=self.current_generation
)
except Area.DoesNotExist:
try:
area = area_source.get(
country=self.country, type__code=area_type,
name__istartswith=area_name,
generation_low__lte=self.current_generation,
generation_high__gte=self.current_generation
)
except Area.DoesNotExist:
return None, False
else:
area.generation_high = self.new_generation
area.save()
_code, code_created = area.codes.get_or_create(type=self.gss_code_type, code=area_gss_code)
return area, code_created
except Area.DoesNotExist:
return None, False

def report_result(self, message, code_created):
print message,
Expand Down

0 comments on commit f4e27f3

Please sign in to comment.