Stop saying "areas" when we mean "area_ids"

"areas" normally means an instance of BroadcastArea or similar, so
we should be more accurate to avoid confusion.
This commit is contained in:
Ben Thorner
2021-08-26 10:42:20 +01:00
parent bdf0fdbd5f
commit de9d1f991b
5 changed files with 25 additions and 28 deletions

View File

@@ -184,8 +184,8 @@ class CustomBroadcastArea(BaseBroadcastArea):
class CustomBroadcastAreas(SerialisedModelCollection):
model = CustomBroadcastArea
def __init__(self, *, areas, polygons):
self.items = areas
def __init__(self, *, area_ids, polygons):
self.items = area_ids
self._polygons = polygons
def __getitem__(self, index):

View File

@@ -88,7 +88,7 @@ class BroadcastMessage(JSONModel):
@property
def areas(self):
library_areas = self.get_areas(areas=self._dict['areas'])
library_areas = self.get_areas(self._dict['areas'])
if library_areas:
if len(library_areas) != len(self._dict['areas']):
@@ -99,7 +99,7 @@ class BroadcastMessage(JSONModel):
return library_areas
return CustomBroadcastAreas(
areas=self._dict['areas'],
area_ids=self._dict['areas'],
polygons=self._dict['simple_polygons'],
)
@@ -201,9 +201,9 @@ class BroadcastMessage(JSONModel):
return round_to_significant_figures(count, 1)
def get_areas(self, areas):
def get_areas(self, area_ids):
return broadcast_area_libraries.get_areas(
areas
area_ids
)
def get_simple_polygons(self, areas):
@@ -216,20 +216,17 @@ class BroadcastMessage(JSONModel):
# combined shapes to keep the point count down
return polygons.smooth.simplify if len(areas) > 1 else polygons
def add_areas(self, *new_areas):
areas = list(OrderedSet(
self._dict['areas'] + list(new_areas)
def add_areas(self, *new_area_ids):
area_ids = list(OrderedSet(
self._dict['areas'] + list(new_area_ids)
))
simple_polygons = self.get_simple_polygons(areas=self.get_areas(areas=areas))
self._update(areas=areas, simple_polygons=simple_polygons.as_coordinate_pairs_lat_long)
simple_polygons = self.get_simple_polygons(areas=self.get_areas(area_ids))
self._update(areas=area_ids, simple_polygons=simple_polygons.as_coordinate_pairs_lat_long)
def remove_area(self, area_to_remove):
areas = [
area for area in self._dict['areas']
if area != area_to_remove
]
simple_polygons = self.get_simple_polygons(areas=self.get_areas(areas=areas))
self._update(areas=areas, simple_polygons=simple_polygons.as_coordinate_pairs_lat_long)
def remove_area(self, area_id):
area_ids = list(set(self._dict['areas']) - {area_id})
simple_polygons = self.get_simple_polygons(areas=self.get_areas(area_ids))
self._update(areas=area_ids, simple_polygons=simple_polygons.as_coordinate_pairs_lat_long)
def _set_status_to(self, status):
broadcast_message_api_client.update_broadcast_message_status(

View File

@@ -678,7 +678,7 @@ def broadcast_message_json(
updated_at=None,
approved_by_id=None,
cancelled_by_id=None,
areas=None,
area_ids=None,
simple_polygons=None,
content=None,
reference=None,
@@ -696,7 +696,7 @@ def broadcast_message_json(
'reference': reference,
'personalisation': {},
'areas': areas or [
'areas': area_ids or [
'ctry19-E92000001', 'ctry19-S92000003',
],
'simple_polygons': simple_polygons or [],

View File

@@ -904,7 +904,7 @@ def test_preview_broadcast_areas_page(
created_by_id=fake_uuid,
service_id=SERVICE_ONE_ID,
status='draft',
areas=areas_selected,
area_ids=areas_selected,
),
)
client_request.login(active_user_create_broadcasts_permission)
@@ -974,7 +974,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
created_by_id=fake_uuid,
service_id=SERVICE_ONE_ID,
status='draft',
areas=['Area one', 'Area two', 'Area three'],
area_ids=['Area one', 'Area two', 'Area three'],
simple_polygons=polygons,
),
)
@@ -1000,7 +1000,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
] == expected_list_items
@pytest.mark.parametrize('areas, expected_list', (
@pytest.mark.parametrize('area_ids, expected_list', (
([], [
'Countries',
'Demo areas',
@@ -1053,7 +1053,7 @@ def test_choose_broadcast_library_page(
service_one,
fake_uuid,
active_user_create_broadcasts_permission,
areas,
area_ids,
expected_list,
):
service_one['permissions'] += ['broadcast']
@@ -1065,7 +1065,7 @@ def test_choose_broadcast_library_page(
created_by_id=fake_uuid,
service_id=SERVICE_ONE_ID,
status='draft',
areas=areas,
area_ids=area_ids,
),
)
client_request.login(active_user_create_broadcasts_permission)
@@ -1108,7 +1108,7 @@ def test_suggested_area_has_correct_link(
created_by_id=fake_uuid,
service_id=SERVICE_ONE_ID,
status='draft',
areas=[
area_ids=[
'wd20-E05004299', # Pitville, a ward of Cheltenham
],
),

View File

@@ -11,7 +11,7 @@ def test_simple_polygons(fake_uuid):
template_id=fake_uuid,
status='draft',
created_by_id=fake_uuid,
areas=[
area_ids=[
# Hackney Central
'wd20-E05009372',
# Hackney Wick
@@ -56,7 +56,7 @@ def test_raises_for_missing_areas(fake_uuid):
template_id=fake_uuid,
status='draft',
created_by_id=fake_uuid,
areas=[
area_ids=[
'wd20-E05009372',
'something else',
],