From b126c3912d9f48d6647d12be1a43ed56a5fa8785 Mon Sep 17 00:00:00 2001 From: Madison Swain-Bowden Date: Tue, 25 Jun 2024 22:09:24 -0700 Subject: [PATCH] Add prompt bypass option for `bulk-add-officers` command --- OpenOversight/app/commands.py | 17 ++++++++++++++--- justfile | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/OpenOversight/app/commands.py b/OpenOversight/app/commands.py index 26edb1e14..fe0db5306 100644 --- a/OpenOversight/app/commands.py +++ b/OpenOversight/app/commands.py @@ -469,8 +469,17 @@ def process_salary(row, officer, compare=False): is_flag=True, help="allow updating normally-static fields like race, birth year, etc.", ) +@click.option( + "--yes", + "-y", + "bypass_prompt", + is_flag=True, + help="bypass the user prompt and immediately add the officers to the database", +) @with_appcontext -def bulk_add_officers(filename, no_create, update_by_name, update_static_fields): +def bulk_add_officers( + filename, no_create, update_by_name, update_static_fields, bypass_prompt +): """Add or update officers from a CSV file.""" encoding = ENCODING_UTF_8 @@ -551,8 +560,10 @@ def bulk_add_officers(filename, no_create, update_by_name, update_static_fields) create_officer_from_row(row, department_id) ImportLog.print_logs() - if current_app.config["ENV"] == "testing" or prompt_yes_no( - "Do you want to commit the above changes?" + if ( + current_app.config["ENV"] == "testing" + or bypass_prompt + or prompt_yes_no("Do you want to commit the above changes?") ): print("Commiting changes.") db.session.commit() diff --git a/justfile b/justfile index b0e733246..14f1afd99 100644 --- a/justfile +++ b/justfile @@ -64,7 +64,7 @@ fresh-start: dotenv {{ RUN_WEB }} python create_db.py {{ RUN_WEB }} flask make-admin-user {{ RUN_WEB }} flask add-department "Seattle Police Department" "SPD" "WA" - {{ RUN_WEB }} flask bulk-add-officers /data/init_data.csv + {{ RUN_WEB }} flask bulk-add-officers -y /data/init_data.csv # Start containers @just up