mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-07 09:29:23 -04:00
Add temporary command to migrate data for "areas"
This will be run with a CSV of all broadcast messages. Since very few users are creating or updating broadcasts, it's highly unlikely we'll encounter a race condition during the update.
This commit is contained in:
@@ -11,5 +11,22 @@ def list_routes():
|
||||
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule)) # noqa
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('csv_path')
|
||||
@with_appcontext
|
||||
def tmp_backfill_areas(csv_path, dry_run=True):
|
||||
import csv
|
||||
|
||||
from app.models.broadcast_message import BroadcastMessage
|
||||
|
||||
for id, service_id in csv.reader(open(csv_path)):
|
||||
message = BroadcastMessage.from_id(id, service_id=service_id)
|
||||
print(f'Updating {message.id}') # noqa
|
||||
|
||||
if not dry_run:
|
||||
message._update_areas(force_override=True)
|
||||
|
||||
|
||||
def setup_commands(application):
|
||||
application.cli.add_command(list_routes)
|
||||
application.cli.add_command(tmp_backfill_areas)
|
||||
|
||||
@@ -240,12 +240,20 @@ class BroadcastMessage(JSONModel):
|
||||
service_id=self.service_id,
|
||||
)
|
||||
|
||||
def _update_areas(self):
|
||||
self._update(areas_2={
|
||||
def _update_areas(self, force_override=False):
|
||||
areas_2 = {
|
||||
'ids': self.area_ids,
|
||||
'names': [area.name for area in self.areas],
|
||||
'simple_polygons': self.simple_polygons.as_coordinate_pairs_lat_long
|
||||
})
|
||||
}
|
||||
|
||||
data = {'areas_2': areas_2}
|
||||
|
||||
# TEMPORARY: while we migrate to a new format for "areas"
|
||||
if force_override:
|
||||
data['force_override'] = True
|
||||
|
||||
self._update(**data)
|
||||
|
||||
def _update(self, **kwargs):
|
||||
broadcast_message_api_client.update_broadcast_message(
|
||||
|
||||
Reference in New Issue
Block a user