fix: expose fallback key for email settings
This commit is contained in:
parent
7c6bdb404e
commit
7e0b16c57d
1 changed files with 17 additions and 5 deletions
|
|
@ -63,6 +63,7 @@ class EmailSettingView(MasterView): # pylint: disable=abstract-method
|
|||
|
||||
form_fields = [
|
||||
"key",
|
||||
"fallback_key",
|
||||
"description",
|
||||
"subject",
|
||||
"sender",
|
||||
|
|
@ -92,9 +93,11 @@ class EmailSettingView(MasterView): # pylint: disable=abstract-method
|
|||
def normalize_setting(self, setting): # pylint: disable=empty-docstring
|
||||
""" """
|
||||
key = setting.__name__
|
||||
setting = setting(self.config)
|
||||
return {
|
||||
"key": key,
|
||||
"description": setting.__doc__,
|
||||
"fallback_key": setting.fallback_key or "",
|
||||
"description": setting.get_description() or "",
|
||||
"subject": self.email_handler.get_auto_subject(
|
||||
key, rendered=False, setting=setting
|
||||
),
|
||||
|
|
@ -158,8 +161,12 @@ class EmailSettingView(MasterView): # pylint: disable=abstract-method
|
|||
f = form
|
||||
super().configure_form(f)
|
||||
|
||||
# fallback_key
|
||||
f.set_readonly("fallback_key")
|
||||
|
||||
# description
|
||||
f.set_readonly("description")
|
||||
f.set_widget("description", "notes")
|
||||
|
||||
# replyto
|
||||
f.set_required("replyto", False)
|
||||
|
|
@ -247,11 +254,12 @@ class EmailSettingView(MasterView): # pylint: disable=abstract-method
|
|||
if self.viewing:
|
||||
setting = context["instance"]
|
||||
context["setting"] = setting
|
||||
|
||||
context["has_html_template"] = self.email_handler.get_auto_body_template(
|
||||
setting["key"], "html"
|
||||
setting["key"], "html", fallback_key=setting["fallback_key"]
|
||||
)
|
||||
context["has_txt_template"] = self.email_handler.get_auto_body_template(
|
||||
setting["key"], "txt"
|
||||
setting["key"], "txt", fallback_key=setting["fallback_key"]
|
||||
)
|
||||
|
||||
return super().render_to_response(template, context)
|
||||
|
|
@ -269,11 +277,15 @@ class EmailSettingView(MasterView): # pylint: disable=abstract-method
|
|||
mode = self.request.params.get("mode", "html")
|
||||
|
||||
if mode == "txt":
|
||||
body = self.email_handler.get_auto_txt_body(key, context)
|
||||
body = self.email_handler.get_auto_txt_body(
|
||||
key, context, fallback_key=setting.fallback_key
|
||||
)
|
||||
self.request.response.content_type = "text/plain"
|
||||
|
||||
else: # html
|
||||
body = self.email_handler.get_auto_html_body(key, context)
|
||||
body = self.email_handler.get_auto_html_body(
|
||||
key, context, fallback_key=setting.fallback_key
|
||||
)
|
||||
|
||||
self.request.response.text = body
|
||||
return self.request.response
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue