mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 05:29:38 -04:00
Switch to using temporary "areas_2" API field
Depends on: https://github.com/alphagov/notifications-api/pull/3312 This is part of a multi-stage migration where we want to repurpose the "areas" field in the existing API to something like "areas_2".
This commit is contained in:
@@ -88,19 +88,21 @@ class BroadcastMessage(JSONModel):
|
||||
|
||||
@property
|
||||
def areas(self):
|
||||
library_areas = self.get_areas(self._dict['areas'])
|
||||
area_ids = self._dict['areas_2']['ids']
|
||||
polygons = self._dict['areas_2']['simple_polygons']
|
||||
library_areas = self.get_areas(area_ids)
|
||||
|
||||
if library_areas:
|
||||
if len(library_areas) != len(self._dict['areas']):
|
||||
if len(library_areas) != len(area_ids):
|
||||
raise RuntimeError(
|
||||
f'BroadcastMessage has {len(self._dict["areas"])} areas '
|
||||
f'BroadcastMessage has {len(area_ids)} areas '
|
||||
f'but {len(library_areas)} found in the library'
|
||||
)
|
||||
return library_areas
|
||||
|
||||
return CustomBroadcastAreas(
|
||||
area_ids=self._dict['areas'],
|
||||
polygons=self._dict['simple_polygons'],
|
||||
area_ids=area_ids,
|
||||
polygons=polygons,
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -218,15 +220,23 @@ class BroadcastMessage(JSONModel):
|
||||
|
||||
def add_areas(self, *new_area_ids):
|
||||
area_ids = list(OrderedSet(
|
||||
self._dict['areas'] + list(new_area_ids)
|
||||
self._dict['areas_2']['ids'] + list(new_area_ids)
|
||||
))
|
||||
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)
|
||||
|
||||
self._update(areas_2={
|
||||
'ids': area_ids,
|
||||
'simple_polygons': simple_polygons.as_coordinate_pairs_lat_long
|
||||
})
|
||||
|
||||
def remove_area(self, area_id):
|
||||
area_ids = list(set(self._dict['areas']) - {area_id})
|
||||
area_ids = list(set(self._dict['areas_2']['ids']) - {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)
|
||||
|
||||
self._update(areas_2={
|
||||
'ids': 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(
|
||||
|
||||
Reference in New Issue
Block a user