Skip to content

Commit cdf21b9

Browse files
authored
Migration for main newsletter content template (#2707)
* Migration for main newsletter content template * Fix a few typos
1 parent 18ddcd6 commit cdf21b9

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

app/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ class Config(object):
340340
# Newsletter templates
341341
NEWSLETTER_CONFIRMATION_EMAIL_TEMPLATE_ID_EN = "c8ee07a2-7cf4-4a32-9cc2-6763b5bc47a6"
342342
NEWSLETTER_CONFIRMATION_EMAIL_TEMPLATE_ID_FR = "109807d5-3a2d-49ca-9bd8-d6eae3ac1770"
343+
NEWSLETTER_EMAIL_TEMPLATE_ID_EN = "c3a0273c-ea55-4de4-a688-018ab909795d"
344+
NEWSLETTER_EMAIL_TEMPLATE_ID_FR = "0422ee2d-0e13-4d6b-a52c-77e59e7dd89c"
343345

344346
# Templates for annual limits
345347
REACHED_ANNUAL_LIMIT_TEMPLATE_ID = "ca6d9205-d923-4198-acdd-d0aa37725c37"
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""
2+
3+
Revision ID: 0496_newsletter_templates
4+
Revises: 0494_update_some_templates
5+
Create Date: 2025-10-21 00:00:00
6+
7+
"""
8+
from datetime import datetime
9+
10+
from alembic import op
11+
from flask import current_app
12+
13+
revision = "0496_newsletter_templates"
14+
down_revision = "0495_newsletter_conf_templates"
15+
16+
newsletter_template_en_id = current_app.config["NEWSLETTER_EMAIL_TEMPLATE_ID_EN"]
17+
newsletter_template_fr_id = current_app.config["NEWSLETTER_EMAIL_TEMPLATE_ID_FR"]
18+
template_ids = [newsletter_template_en_id, newsletter_template_fr_id]
19+
20+
def upgrade():
21+
template_insert = """
22+
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject,
23+
created_by_id, version, process_type, hidden)
24+
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false)
25+
"""
26+
template_history_insert = """
27+
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject,
28+
created_by_id, version, process_type, hidden)
29+
VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false)
30+
"""
31+
32+
template_content_en = "\n".join(
33+
[
34+
"((newsletter_content))",
35+
"",
36+
"[Unsubscribe](((unsubscribe_link))) / [Change language](((change_language_link)))"
37+
]
38+
)
39+
40+
template_content_fr = "\n".join(
41+
[
42+
"((newsletter_content))",
43+
"",
44+
"[Se désabonner](((unsubscribe_link))) / [Changer la langue](((change_language_link)))"
45+
]
46+
)
47+
48+
templates = [
49+
{
50+
"id": newsletter_template_en_id,
51+
"name": "EN Notify Newsletter",
52+
"subject": f"Newsletter ((newsletter_number))",
53+
"content": template_content_en,
54+
"template_type": "email",
55+
"process_type": "normal",
56+
},
57+
{
58+
"id": newsletter_template_fr_id,
59+
"name": "FR Notify Newsletter",
60+
"subject": "Infolettre ((newsletter_number))",
61+
"content": template_content_fr,
62+
"template_type": "email",
63+
"process_type": "normal",
64+
},
65+
]
66+
67+
for template in templates:
68+
op.execute(
69+
template_insert.format(
70+
template["id"],
71+
template["name"],
72+
template["template_type"],
73+
datetime.utcnow(),
74+
template["content"],
75+
current_app.config["NOTIFY_SERVICE_ID"],
76+
template["subject"],
77+
current_app.config["NOTIFY_USER_ID"],
78+
template["process_type"],
79+
)
80+
)
81+
82+
op.execute(
83+
template_history_insert.format(
84+
template["id"],
85+
template["name"],
86+
template["template_type"],
87+
datetime.utcnow(),
88+
template["content"],
89+
current_app.config["NOTIFY_SERVICE_ID"],
90+
template["subject"],
91+
current_app.config["NOTIFY_USER_ID"],
92+
template["process_type"],
93+
)
94+
)
95+
96+
def downgrade():
97+
for template_id in template_ids:
98+
op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id))
99+
op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id))
100+
op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(template_id))
101+
op.execute("DELETE FROM templates_history WHERE id = '{}'".format(template_id))
102+
op.execute("DELETE FROM templates WHERE id = '{}'".format(template_id))
103+

0 commit comments

Comments
 (0)