Skip to content

Commit

Permalink
Fix #1361 Preserve custom thank you email template if chosen
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsimpson committed Jun 22, 2024
1 parent fec7de7 commit e649608
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions subscribie/blueprints/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,22 +1692,26 @@ def edit_welcome_email():
custom_template = EmailTemplate()
database.session.add(custom_template)

if form.validate_on_submit() and form.use_custom_welcome_email.data is True:
if form.validate_on_submit():
new_custom_template = form.template.data
# Validate template syntax
env = jinja2.Environment()
try:
env.parse(new_custom_template)
# Store the validated template
custom_template.custom_welcome_email_template = new_custom_template
custom_template.use_custom_welcome_email = True
if form.use_custom_welcome_email.data is True:
custom_template.use_custom_welcome_email = True
else:
custom_template.use_custom_welcome_email = False
flash("Email template has been saved.")
flash("Using custom template for welcome email")
except jinja2.exceptions.TemplateSyntaxError as e:
form.template.errors.append(e)

else:
custom_template.use_custom_welcome_email = False
if custom_template.use_custom_welcome_email is not True:
custom_template.use_custom_welcome_email = False
if request.method == "POST":
flash("Using default template for welcome email")

Expand Down

0 comments on commit e649608

Please sign in to comment.