mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 17:38:50 -04:00
Refactor logic to identify types of areas
I did consider whether to store this explicitly in the SQLite DB, but this is less effort for now and we can always switch to that more robust approach in future if we need to.
This commit is contained in:
@@ -86,6 +86,14 @@ class BroadcastArea(BaseBroadcastArea, SortableMixin):
|
||||
def __init__(self, row):
|
||||
self.id, self.name, self._count_of_phones, self.library_id = row
|
||||
|
||||
@cached_property
|
||||
def is_lower_tier_local_authority(self):
|
||||
return self.id.startswith('lad20-') and self.parent
|
||||
|
||||
@cached_property
|
||||
def is_electoral_ward(self):
|
||||
return self.id.startswith('wd20-')
|
||||
|
||||
@classmethod
|
||||
def from_row_with_simple_polygons(cls, row):
|
||||
instance = cls(row[:4])
|
||||
|
||||
@@ -24,7 +24,7 @@ def _convert_custom_areas_to_wards(areas):
|
||||
|
||||
def _aggregate_wards_by_local_authority(areas):
|
||||
return {
|
||||
area.parent if area.id.startswith('wd20-')
|
||||
area.parent if area.is_electoral_ward
|
||||
else area for area in areas
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ def _cluster_lower_tier_authorities(areas):
|
||||
|
||||
for area in areas:
|
||||
# group lower tier authorities by "county"
|
||||
if area.id.startswith('lad20-') and area.parent:
|
||||
if area.is_lower_tier_local_authority:
|
||||
result[area.parent] += [area]
|
||||
# leave countries, unitary authorities as-is
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user