Files
notifications-admin/app/commands.py
Ben Thorner 9667433b7e 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.
2021-08-26 13:08:05 +01:00

33 lines
955 B
Python

import click
from flask import current_app
from flask.cli import with_appcontext
@click.command('list-routes')
@with_appcontext
def list_routes():
"""List URLs of all application routes."""
for rule in sorted(current_app.url_map.iter_rules(), key=lambda r: r.rule):
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)