From 447c69d3d93ba36570ea62f579125236916c0620 Mon Sep 17 00:00:00 2001 From: Jumana B Date: Mon, 8 Jul 2024 10:38:49 -0400 Subject: [PATCH] Add few categories (#2206) * Add few categories * fix * Rename priority * Fix french translation --- .../versions/0454_add_template_category.py | 2 +- .../versions/0455_add_starter_category.py | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/0455_add_starter_category.py diff --git a/migrations/versions/0454_add_template_category.py b/migrations/versions/0454_add_template_category.py index 1ba66c6c8d..b98339fb9f 100644 --- a/migrations/versions/0454_add_template_category.py +++ b/migrations/versions/0454_add_template_category.py @@ -12,7 +12,7 @@ from flask import current_app from sqlalchemy.dialects import postgresql -revision = "0454_add_template_categories" +revision = "0454_add_template_category" down_revision = "0453_set_supports_international" diff --git a/migrations/versions/0455_add_starter_category.py b/migrations/versions/0455_add_starter_category.py new file mode 100644 index 0000000000..efe74bf2d0 --- /dev/null +++ b/migrations/versions/0455_add_starter_category.py @@ -0,0 +1,100 @@ +""" + +Revision ID: 0455_add_starter_category +Revises: 0454_add_template_category +Create Date: 2024-06-11 13:32:00 +""" +from alembic import op + +revision = "0455_add_starter_category" +down_revision = "0454_add_template_category" + +CAT_ALERT_ID = "1d8ce435-a7e5-431b-aaa2-a418bc4d14f9" +CAT_AUTH_ID = "b6c42a7e-2a26-4a07-802b-123a5c3198a9" +CAT_AUTO_ID = "977e2a00-f957-4ff0-92f2-ca3286b24786" +CAT_DECISION_ID = "e81678c0-4897-4111-b9d0-172f6b595f89" +CAT_INFO_ID = "207b293c-2ae5-48e8-836d-fcabd60b2153" +CAT_REMINDER_ID = "edb966f3-4a4c-47a4-96ab-05ff259b919c" +CAT_REQUEST_ID = "e0b8fbe5-f435-4977-8fc8-03f13d9296a5" +CAT_STATUS_ID = "55eb1137-6dc6-4094-9031-f61124a279dc" +CAT_TEST_ID = "7c16aa95-e2e1-4497-81d6-04c656520fe4" + +# List of category IDs +category_ids = [ + CAT_ALERT_ID, + CAT_AUTH_ID, + CAT_AUTO_ID, + CAT_DECISION_ID, + CAT_INFO_ID, + CAT_REMINDER_ID, + CAT_REQUEST_ID, + CAT_STATUS_ID, + CAT_TEST_ID, +] + +# Corresponding English and French names and descriptions and process_type +category_data = [ + ("Alert", "Alerte", "System checks and monitoring", "Contrôles et suivi du système", "medium", "medium"), + ( + "Authentication", + "Authentification", + "Password resets and two factor verification", + "Réinitialisations de mots de passe et vérification à deux facteurs", + "priority", + "priority", + ), + ( + "Automatic reply", + "Réponse automatique", + "No-reply and confirmation messages", + "Messages auxquels il est impossible de répondre et messages de confirmation", + "priority", + "priority", + ), + ("Decision", "Décision", "Permits, documents and results", "Permis, documents et résultats", "low", "low"), + ( + "Information blast", + "Information de masse", + "Newsletters, surveys and general information", + "Infolettres, sondages et renseignements généraux", + "bulk", + "bulk", + ), + ("Reminder", "Rappel", "Appointments and deadlines", "Rendez-vous et échéances", "normal", "normal"), + ("Request", "Demande", "Request: Follow up and next steps", "Suivis et prochaines étapes", "normal", "normal"), + ("Status update", "État d’avancement", "Changes and progress", "Changements et progrès", "normal", "normal"), + ("Test", "Test", "Practice messages", "Messages à titre d’entraînement", "bulk", "bulk"), +] + + +def upgrade(): + # Insert new process_type + op.execute("INSERT INTO template_process_type (name) VALUES ('low')") + op.execute("INSERT INTO template_process_type (name) VALUES ('medium')") + op.execute("INSERT INTO template_process_type (name) VALUES ('high')") + + def insert_statement(id, name_en, name_fr, description_en, description_fr, sms_process_type, email_process_type): + # Escape single quotes in string values + name_fr = name_fr.replace("'", "''") + description_fr = description_fr.replace("'", "''") + + return f""" + INSERT INTO template_categories + (id, name_en, name_fr, description_en, description_fr, sms_process_type, email_process_type, hidden, created_at) + VALUES + ('{id}', '{name_en}', '{name_fr}', '{description_en}', '{description_fr}', '{sms_process_type}', '{email_process_type}', false, now()) + """ + + for id, (name_en, name_fr, desc_en, desc_fr, sms_process_type, email_process_type) in zip(category_ids, category_data): + stmt = insert_statement(id, name_en, name_fr, desc_en, desc_fr, sms_process_type, email_process_type) + op.execute(stmt) + + +def downgrade(): + for id in category_ids: + op.execute(f"DELETE FROM template_categories WHERE id = '{id}'") + + # Delete process_type + op.execute("DELETE FROM template_process_type WHERE name = 'low'") + op.execute("DELETE FROM template_process_type WHERE name = 'medium'") + op.execute("DELETE FROM template_process_type WHERE name = 'high'")