Rewrite the email module version selection logic

pull/22390/head
Yansong Zhang 10 months ago
parent 4de94050a1
commit 1a5a749bdd

@ -29,62 +29,43 @@ def send_change_mail_task(language: str, to: str, code: str, phase: str):
"old_email": {
"subject": "检测您现在的邮箱",
"template_with_brand": "change_mail_confirm_old_template_zh-CN.html",
"template_without_brand": "without-brand/change_mail_confirm_old_template_zh-CN.html"
"template_without_brand": "without-brand/change_mail_confirm_old_template_zh-CN.html",
},
"new_email": {
"subject": "确认您的邮箱地址变更",
"template_with_brand": "change_mail_confirm_new_template_zh-CN.html",
"template_without_brand": "without-brand/change_mail_confirm_new_template_zh-CN.html"
}
"template_without_brand": "without-brand/change_mail_confirm_new_template_zh-CN.html",
},
},
"en": {
"old_email": {
"subject": "Check your current email",
"template_with_brand": "change_mail_confirm_old_template_en-US.html",
"template_without_brand": "without-brand/change_mail_confirm_old_template_en-US.html"
"template_without_brand": "without-brand/change_mail_confirm_old_template_en-US.html",
},
"new_email": {
"subject": "Confirm your new email address",
"template_with_brand": "change_mail_confirm_new_template_en-US.html",
"template_without_brand": "without-brand/change_mail_confirm_new_template_en-US.html"
}
}
"template_without_brand": "without-brand/change_mail_confirm_new_template_en-US.html",
},
},
}
# send change email mail using different languages
try:
system_features = FeatureService.get_system_features()
if language == "zh-Hans":
if phase == "old_email":
subject = "检测您现在的邮箱"
if system_features.branding.enabled:
template = "without-brand/change_mail_confirm_old_template_zh-CN.html"
else:
template = "change_mail_confirm_old_template_zh-CN.html"
elif phase == "new_email":
subject = "确认您的邮箱地址变更"
if system_features.branding.enabled:
template = "without-brand/change_mail_confirm_new_template_zh-CN.html"
else:
template = "change_mail_confirm_new_template_zh-CN.html"
else:
lang_key = "zh-Hans" if language == "zh-Hans" else "en"
if phase not in ["old_email", "new_email"]:
raise ValueError("Invalid phase")
else:
if phase == "old_email":
subject = "Check your current email"
if system_features.branding.enabled:
template = "without-brand/change_mail_confirm_old_template_en-US.html"
else:
template = "change_mail_confirm_old_template_en-US.html"
elif phase == "new_email":
subject = "Confirm your new email address"
config = email_config[lang_key][phase]
subject = config["subject"]
if system_features.branding.enabled:
template = "without-brand/change_mail_confirm_new_template_en-US.html"
else:
template = "change_mail_confirm_new_template_en-US.html"
template = config["template_without_brand"]
else:
raise ValueError("Invalid phase")
template = config["template_with_brand"]
html_content = render_template(template, to=to, code=code)
mail.send(to=to, subject=subject, html=html_content)

Loading…
Cancel
Save