From d38c5162e5c198dc9e70827cfcc65f3f2d4145af Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 8 May 2026 14:07:14 +0100 Subject: [PATCH 1/2] Python now demands you put (?i) at the start. --- mapit_gb/controls/possible-future.py | 2 +- mapit_gb/management/commands/mapit_UK_import_boundary_line.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mapit_gb/controls/possible-future.py b/mapit_gb/controls/possible-future.py index 54105256..8a6b2663 100644 --- a/mapit_gb/controls/possible-future.py +++ b/mapit_gb/controls/possible-future.py @@ -21,7 +21,7 @@ def check(name, type, country, geometry, **args): # Make sure CEDs are loaded *after* CTY area_within = Area.objects.filter(type__code='CTY', polygons__polygon__contains=geometry.geos.point_on_surface)[0] - if re.search('Buckinghamshire(?i)', area_within.name): + if re.search('(?i)Buckinghamshire', area_within.name): return True return False diff --git a/mapit_gb/management/commands/mapit_UK_import_boundary_line.py b/mapit_gb/management/commands/mapit_UK_import_boundary_line.py index b7bc5ac0..43c98132 100644 --- a/mapit_gb/management/commands/mapit_UK_import_boundary_line.py +++ b/mapit_gb/management/commands/mapit_UK_import_boundary_line.py @@ -52,7 +52,7 @@ def handle_label(self, filename, **options): if not isinstance(name, str): name = name.decode('iso-8859-1') - name = re.sub(r'\s*\(DET( NO \d+|)\)\s*(?i)', '', name) + name = re.sub(r'(?i)\s*\(DET( NO \d+|)\)\s*', '', name) name = re.sub(r'\s+', ' ', name) ons_code = feat['CODE'].value if feat['CODE'].value not in ('999999', '999999999') else None From 137da940f11a41613927557fee440f04749d624f Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 8 May 2026 14:08:21 +0100 Subject: [PATCH 2/2] [UK] May 2026 Boundary-Line import. Wales constituencies no longer have a parent. --- mapit_gb/controls/2026-05.py | 56 +++++++++++++++++++ .../commands/mapit_UK_find_parents.py | 2 - 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 mapit_gb/controls/2026-05.py diff --git a/mapit_gb/controls/2026-05.py b/mapit_gb/controls/2026-05.py new file mode 100644 index 00000000..02067eae --- /dev/null +++ b/mapit_gb/controls/2026-05.py @@ -0,0 +1,56 @@ +# A control file for importing Boundary-Line. +# CEDs (county council electoral divisions) don't have ONS codes, so we have to +# have something manual as this is a year of county council boundary changes. +# +# OS release notes are at +# https://docs.os.uk/os-downloads/products/areas-and-zones-portfolio/boundary-line/release-notes/may-2026 +# +# The following English counties have had full boundary changes: +# Essex, Norfolk, Suffolk. +# Unitaries with boundary changes are the following, but we spot them +# automatically by GSS code: Milton Keynes, Swindon, Thurrock. +# And lots of MTDs as well. + +from mapit.models import Area, Generation + +COUNTIES_CHANGED = ["%s County Council" % c for c in [ + 'Essex', 'Norfolk', 'Suffolk' +]] +COUNTIES_NOT_CHANGED = ["%s County Council" % c for c in [ + 'Cambridgeshire', 'Derbyshire', 'Devon', 'Dorset', 'East Sussex', + 'Gloucestershire', 'Hampshire', 'Hertfordshire', 'Kent', 'Lancashire', + 'Leicestershire', 'Lincolnshire', 'Oxfordshire', "Northamptonshire", + "North Yorkshire", 'Nottinghamshire', "Somerset", 'Staffordshire', + "Surrey", 'Warwickshire', 'West Sussex', 'Worcestershire' +]] + + +def code_version(): + return 'gss' + + +def check(name, type, country, geometry, ons_code, commit, **args): + """Should return True if this area is NEW, False if we should match against + an ONS/unit_id code, or an Area to be used as an override instead.""" + + current = Generation.objects.current() + if not current: # Fresh import + return False + + # We already have ONS codes in our system for the Welsh Parliament, + # and we want these to go in as new entries + if type == 'WAC': + return True + + # Some UTAs have had boundary changes, but have ONS codes and so can be + # ignored/ detected that way. + if type != 'CED': + return False + + # Make sure CEDs are loaded *after* CTY + area_within = Area.objects.filter(type__code='CTY', polygons__polygon__contains=geometry.geos.point_on_surface)[0] + if area_within.name in COUNTIES_CHANGED: + return True + elif area_within.name in COUNTIES_NOT_CHANGED: + return False + raise Exception("Bad county name given: %s" % area_within.name) diff --git a/mapit_gb/management/commands/mapit_UK_find_parents.py b/mapit_gb/management/commands/mapit_UK_find_parents.py index 50cffe57..2c1df738 100644 --- a/mapit_gb/management/commands/mapit_UK_find_parents.py +++ b/mapit_gb/management/commands/mapit_UK_find_parents.py @@ -26,8 +26,6 @@ class Command(FindParentsCommand): 'UTW': ('UTA', 'COI'), # A Scottish Parliament constituency's parent is a Scottish Parliament region: 'SPC': 'SPE', - # A Welsh Assembly constituency's parent is a Welsh Assembly region: - 'WAC': 'WAE', # A Civil Parish's parent is one of: # District council # Unitary Authority