mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 16:19:49 -04:00
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:
@@ -184,8 +184,8 @@ class CustomBroadcastArea(BaseBroadcastArea):
|
|||||||
class CustomBroadcastAreas(SerialisedModelCollection):
|
class CustomBroadcastAreas(SerialisedModelCollection):
|
||||||
model = CustomBroadcastArea
|
model = CustomBroadcastArea
|
||||||
|
|
||||||
def __init__(self, *, areas, polygons):
|
def __init__(self, *, area_ids, polygons):
|
||||||
self.items = areas
|
self.items = area_ids
|
||||||
self._polygons = polygons
|
self._polygons = polygons
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class BroadcastMessage(JSONModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def areas(self):
|
def areas(self):
|
||||||
library_areas = self.get_areas(areas=self._dict['areas'])
|
library_areas = self.get_areas(self._dict['areas'])
|
||||||
|
|
||||||
if library_areas:
|
if library_areas:
|
||||||
if len(library_areas) != len(self._dict['areas']):
|
if len(library_areas) != len(self._dict['areas']):
|
||||||
@@ -99,7 +99,7 @@ class BroadcastMessage(JSONModel):
|
|||||||
return library_areas
|
return library_areas
|
||||||
|
|
||||||
return CustomBroadcastAreas(
|
return CustomBroadcastAreas(
|
||||||
areas=self._dict['areas'],
|
area_ids=self._dict['areas'],
|
||||||
polygons=self._dict['simple_polygons'],
|
polygons=self._dict['simple_polygons'],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -201,9 +201,9 @@ class BroadcastMessage(JSONModel):
|
|||||||
|
|
||||||
return round_to_significant_figures(count, 1)
|
return round_to_significant_figures(count, 1)
|
||||||
|
|
||||||
def get_areas(self, areas):
|
def get_areas(self, area_ids):
|
||||||
return broadcast_area_libraries.get_areas(
|
return broadcast_area_libraries.get_areas(
|
||||||
areas
|
area_ids
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_simple_polygons(self, areas):
|
def get_simple_polygons(self, areas):
|
||||||
@@ -216,20 +216,17 @@ class BroadcastMessage(JSONModel):
|
|||||||
# combined shapes to keep the point count down
|
# combined shapes to keep the point count down
|
||||||
return polygons.smooth.simplify if len(areas) > 1 else polygons
|
return polygons.smooth.simplify if len(areas) > 1 else polygons
|
||||||
|
|
||||||
def add_areas(self, *new_areas):
|
def add_areas(self, *new_area_ids):
|
||||||
areas = list(OrderedSet(
|
area_ids = list(OrderedSet(
|
||||||
self._dict['areas'] + list(new_areas)
|
self._dict['areas'] + list(new_area_ids)
|
||||||
))
|
))
|
||||||
simple_polygons = self.get_simple_polygons(areas=self.get_areas(areas=areas))
|
simple_polygons = self.get_simple_polygons(areas=self.get_areas(area_ids))
|
||||||
self._update(areas=areas, simple_polygons=simple_polygons.as_coordinate_pairs_lat_long)
|
self._update(areas=area_ids, simple_polygons=simple_polygons.as_coordinate_pairs_lat_long)
|
||||||
|
|
||||||
def remove_area(self, area_to_remove):
|
def remove_area(self, area_id):
|
||||||
areas = [
|
area_ids = list(set(self._dict['areas']) - {area_id})
|
||||||
area for area in self._dict['areas']
|
simple_polygons = self.get_simple_polygons(areas=self.get_areas(area_ids))
|
||||||
if area != area_to_remove
|
self._update(areas=area_ids, simple_polygons=simple_polygons.as_coordinate_pairs_lat_long)
|
||||||
]
|
|
||||||
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 _set_status_to(self, status):
|
def _set_status_to(self, status):
|
||||||
broadcast_message_api_client.update_broadcast_message_status(
|
broadcast_message_api_client.update_broadcast_message_status(
|
||||||
|
|||||||
@@ -678,7 +678,7 @@ def broadcast_message_json(
|
|||||||
updated_at=None,
|
updated_at=None,
|
||||||
approved_by_id=None,
|
approved_by_id=None,
|
||||||
cancelled_by_id=None,
|
cancelled_by_id=None,
|
||||||
areas=None,
|
area_ids=None,
|
||||||
simple_polygons=None,
|
simple_polygons=None,
|
||||||
content=None,
|
content=None,
|
||||||
reference=None,
|
reference=None,
|
||||||
@@ -696,7 +696,7 @@ def broadcast_message_json(
|
|||||||
'reference': reference,
|
'reference': reference,
|
||||||
|
|
||||||
'personalisation': {},
|
'personalisation': {},
|
||||||
'areas': areas or [
|
'areas': area_ids or [
|
||||||
'ctry19-E92000001', 'ctry19-S92000003',
|
'ctry19-E92000001', 'ctry19-S92000003',
|
||||||
],
|
],
|
||||||
'simple_polygons': simple_polygons or [],
|
'simple_polygons': simple_polygons or [],
|
||||||
|
|||||||
@@ -904,7 +904,7 @@ def test_preview_broadcast_areas_page(
|
|||||||
created_by_id=fake_uuid,
|
created_by_id=fake_uuid,
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
status='draft',
|
status='draft',
|
||||||
areas=areas_selected,
|
area_ids=areas_selected,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
client_request.login(active_user_create_broadcasts_permission)
|
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,
|
created_by_id=fake_uuid,
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
status='draft',
|
status='draft',
|
||||||
areas=['Area one', 'Area two', 'Area three'],
|
area_ids=['Area one', 'Area two', 'Area three'],
|
||||||
simple_polygons=polygons,
|
simple_polygons=polygons,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -1000,7 +1000,7 @@ def test_preview_broadcast_areas_page_with_custom_polygons(
|
|||||||
] == expected_list_items
|
] == expected_list_items
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('areas, expected_list', (
|
@pytest.mark.parametrize('area_ids, expected_list', (
|
||||||
([], [
|
([], [
|
||||||
'Countries',
|
'Countries',
|
||||||
'Demo areas',
|
'Demo areas',
|
||||||
@@ -1053,7 +1053,7 @@ def test_choose_broadcast_library_page(
|
|||||||
service_one,
|
service_one,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
active_user_create_broadcasts_permission,
|
active_user_create_broadcasts_permission,
|
||||||
areas,
|
area_ids,
|
||||||
expected_list,
|
expected_list,
|
||||||
):
|
):
|
||||||
service_one['permissions'] += ['broadcast']
|
service_one['permissions'] += ['broadcast']
|
||||||
@@ -1065,7 +1065,7 @@ def test_choose_broadcast_library_page(
|
|||||||
created_by_id=fake_uuid,
|
created_by_id=fake_uuid,
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
status='draft',
|
status='draft',
|
||||||
areas=areas,
|
area_ids=area_ids,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
client_request.login(active_user_create_broadcasts_permission)
|
client_request.login(active_user_create_broadcasts_permission)
|
||||||
@@ -1108,7 +1108,7 @@ def test_suggested_area_has_correct_link(
|
|||||||
created_by_id=fake_uuid,
|
created_by_id=fake_uuid,
|
||||||
service_id=SERVICE_ONE_ID,
|
service_id=SERVICE_ONE_ID,
|
||||||
status='draft',
|
status='draft',
|
||||||
areas=[
|
area_ids=[
|
||||||
'wd20-E05004299', # Pitville, a ward of Cheltenham
|
'wd20-E05004299', # Pitville, a ward of Cheltenham
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ def test_simple_polygons(fake_uuid):
|
|||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
status='draft',
|
status='draft',
|
||||||
created_by_id=fake_uuid,
|
created_by_id=fake_uuid,
|
||||||
areas=[
|
area_ids=[
|
||||||
# Hackney Central
|
# Hackney Central
|
||||||
'wd20-E05009372',
|
'wd20-E05009372',
|
||||||
# Hackney Wick
|
# Hackney Wick
|
||||||
@@ -56,7 +56,7 @@ def test_raises_for_missing_areas(fake_uuid):
|
|||||||
template_id=fake_uuid,
|
template_id=fake_uuid,
|
||||||
status='draft',
|
status='draft',
|
||||||
created_by_id=fake_uuid,
|
created_by_id=fake_uuid,
|
||||||
areas=[
|
area_ids=[
|
||||||
'wd20-E05009372',
|
'wd20-E05009372',
|
||||||
'something else',
|
'something else',
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user