diff --git a/apps/acls/notifications.py b/apps/acls/notifications.py index dc2e32e0a..ac8b7e4c6 100644 --- a/apps/acls/notifications.py +++ b/apps/acls/notifications.py @@ -17,8 +17,8 @@ class UserLoginReminderMsg(UserMessage): {"name": "city", "label": _('Login city'), "default": "北京"}, {"name": "username", "label": _('User'), "default": "zhangsan"}, {"name": "ip", "label": "IP", "default": "8.8.8.8"}, - {"name": "recipient_name", "label": '接收人名称', "default": "zhangsan"}, - {"name": "recipient_username", "label": '接收人用户名', "default": "张三"}, + {"name": "recipient_name", "label": _("Recipient name"), "default": "zhangsan"}, + {"name": "recipient_username", "label": _("Recipient username"), "default": "张三"}, {"name": "user_agent", "label": _('User agent'), "default": "Mozilla/5.0"}, {"name": "acl_name", "label": _('ACL name'), "default": "login acl"}, {"name": "login_from", "label": _('Login from'), "default": "web"}, @@ -68,8 +68,8 @@ class AssetLoginReminderMsg(UserMessage): {"name": "username", "label": _('User'), "default": "zhangsan"}, {"name": "name", "label": _('Name'), "default": "zhangsan"}, {"name": "asset", "label": _('Asset'), "default": "dev server"}, - {"name": "recipient_name", "label": '接收人名称', "default": "zhangsan"}, - {"name": "recipient_username", "label": '接收人用户名', "default": "张三"}, + {"name": "recipient_name", "label": _('Recipient name'), "default": "zhangsan"}, + {"name": "recipient_username", "label": _('Recipient username'), "default": "张三"}, {"name": "account", "label": _('Account Input username'), "default": "root"}, {"name": "account_name", "label": _('Account name'), "default": "root"}, {"name": "acl_name", "label": _('ACL name'), "default": "login acl"}, diff --git a/apps/authentication/notifications.py b/apps/authentication/notifications.py index c509c295d..d5aceadc6 100644 --- a/apps/authentication/notifications.py +++ b/apps/authentication/notifications.py @@ -1,4 +1,4 @@ -from django.utils.translation import gettext as _ +from django.utils.translation import gettext_lazy as _ from common.utils import get_logger from common.utils.timezone import local_now_display @@ -35,7 +35,7 @@ class DifferentCityLoginMessage(UserMessage): ) message = custom_render_to_string(self.template_name, context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message } @@ -78,7 +78,7 @@ class OAuthBindMessage(UserMessage): ) message = custom_render_to_string(self.template_name, context) return { - 'subject': subject, + 'subject': str(subject), 'message': message } diff --git a/apps/i18n/lina/en.json b/apps/i18n/lina/en.json index 7f2d92a66..cbb8baa85 100644 --- a/apps/i18n/lina/en.json +++ b/apps/i18n/lina/en.json @@ -1619,5 +1619,7 @@ "setVariable": "Set variable", "userId": "User ID", "userName": "User name", - "description": "No data yet" + "description": "No data yet", + "MsgTemplate": "Msg Template", + "TemplateVariablesHelpText": "You can select a template and use {{ key }} within the template content to read built-in variables.Note: only the {{ }} syntax is supported; other syntaxes such as {% if title %} are not supported." } diff --git a/apps/i18n/lina/zh.json b/apps/i18n/lina/zh.json index 5c6d0628e..986d84f1e 100644 --- a/apps/i18n/lina/zh.json +++ b/apps/i18n/lina/zh.json @@ -1628,5 +1628,8 @@ "setVariable": "设置参数", "userId": "用户ID", "userName": "用户名", - "description": "暂无数据" + "description": "暂无数据", + "MsgTemplate": "消息模板", + "Example": "示例值", + "TemplateVariablesHelpText": "您可以选择一个模板在模板内容中使用 {{ key }} 读取内置变量,注意:只支持 {{ }} 语法,其他语法不支持。例如 {% if title %}" } diff --git a/apps/users/notifications.py b/apps/users/notifications.py index 8c00040b2..834d38639 100644 --- a/apps/users/notifications.py +++ b/apps/users/notifications.py @@ -4,7 +4,7 @@ from urllib.parse import urljoin from django.conf import settings from django.template.loader import render_to_string from django.utils import timezone -from django.utils.translation import gettext as _ +from django.utils.translation import gettext_lazy as _ from common.utils import reverse, get_request_ip_or_data, get_request_user_agent from common.views.template import custom_render_to_string @@ -12,7 +12,7 @@ from notifications.notifications import UserMessage class UserCreatedMsg(UserMessage): - subject = str(settings.EMAIL_CUSTOM_USER_CREATED_SUBJECT) + subject = settings.EMAIL_CUSTOM_USER_CREATED_SUBJECT template_name = 'users/_msg_user_created.html' contexts = [ {"name": "honorific", "label": _('Honorific'), "default": "zhangsan"}, @@ -88,7 +88,7 @@ class ResetPasswordMsg(UserMessage): } message = render_to_string('authentication/_msg_reset_password.html', context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message } @@ -123,7 +123,7 @@ class ResetPasswordSuccessMsg(UserMessage): } message = custom_render_to_string(self.template_name, context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message } @@ -162,7 +162,7 @@ class ResetPublicKeySuccessMsg(UserMessage): } message = custom_render_to_string(self.template_name, context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message } @@ -206,7 +206,7 @@ class PasswordExpirationReminderMsg(UserMessage): } message = custom_render_to_string(self.template_name, context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message } @@ -234,7 +234,7 @@ class UserExpirationReminderMsg(UserMessage): } message = render_to_string(self.template_name, context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message } @@ -261,7 +261,7 @@ class ResetSSHKeyMsg(UserMessage): } message = custom_render_to_string(self.template_name, context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message } @@ -287,7 +287,7 @@ class ResetMFAMsg(UserMessage): } message = custom_render_to_string('users/_msg_reset_mfa.html', context) return { - 'subject': self.subject, + 'subject': str(self.subject), 'message': message }