2021-08-26 12:47:36 +01:00
|
|
|
import click
|
2017-11-06 13:07:21 +00:00
|
|
|
from flask import current_app
|
2021-08-26 12:47:36 +01:00
|
|
|
from flask.cli import with_appcontext
|
2017-11-06 13:07:21 +00:00
|
|
|
|
|
|
|
|
|
2021-08-26 12:47:36 +01:00
|
|
|
@click.command('list-routes')
|
|
|
|
|
@with_appcontext
|
2017-11-06 13:07:21 +00:00
|
|
|
def list_routes():
|
|
|
|
|
"""List URLs of all application routes."""
|
|
|
|
|
for rule in sorted(current_app.url_map.iter_rules(), key=lambda r: r.rule):
|
2018-01-04 10:22:37 +00:00
|
|
|
print("{:10} {}".format(", ".join(rule.methods - set(['OPTIONS', 'HEAD'])), rule.rule)) # noqa
|
2017-11-06 13:07:21 +00:00
|
|
|
|
|
|
|
|
|
2021-08-26 12:50:47 +01:00
|
|
|
@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)
|
|
|
|
|
|
|
|
|
|
|
2017-11-06 13:07:21 +00:00
|
|
|
def setup_commands(application):
|
2021-08-26 12:47:36 +01:00
|
|
|
application.cli.add_command(list_routes)
|
2021-08-26 12:50:47 +01:00
|
|
|
application.cli.add_command(tmp_backfill_areas)
|