Skip to content

Commit

Permalink
Improve default body text for email publication to allow translations (
Browse files Browse the repository at this point in the history
…senaite#2153)

* Added template variables for lab name/address

* Default template updated

* Use only lab name in default body text

* Changed labels and descriptions

* Wrap into message factory
  • Loading branch information
ramonski authored Sep 30, 2022
1 parent ab07811 commit 5609a01
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/bika/lims/browser/publish/emailview.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ def email_body(self):
body = setup.getEmailBodySamplePublication()
template_context = {
"client_name": self.client_name,
"lab_name": self.lab_name,
"lab_address": self.lab_address,
}
rendered_body = self.render_email_template(
body, template_context=template_context)
Expand Down Expand Up @@ -361,6 +363,18 @@ def client_name(self):
"""
return safe_unicode(self.context.Title())

@property
def lab_address(self):
"""Returns the laboratory print address
"""
return "<br/>".join(self.laboratory.getPrintAddress())

@property
def lab_name(self):
"""Returns the laboratory name
"""
return self.laboratory.getName()

@property
def exit_url(self):
"""Exit URL for redirect
Expand Down Expand Up @@ -484,7 +498,7 @@ def render_email_template(self, template, template_context=None):
"""

# allow to add translation for initial template
template = self.context.translate(template)
template = self.context.translate(_(template))
recipients = self.email_recipients_and_responsibles
if template_context is None:
template_context = {
Expand Down
11 changes: 8 additions & 3 deletions src/bika/lims/content/bikasetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,15 @@ def getCounterTypes(self, instance=None):
# Needed to fetch the default value from the registry
edit_accessor="getEmailBodySamplePublication",
widget=RichWidget(
label=_("Email body for Sample publication notifications"),
label=_(
"label_bikasetup_email_body_sample_publication",
"Email body for Sample publication notifications"),
description=_(
"The default text that is used for the publication email. "
" sending publication reports."),
"description_bikasetup_email_body_sample_publication",
default="Set the email body text to be used by default when "
"sending out result reports to the selected recipients. "
"You can use reserved keywords: "
"$client_name, $recipients, $lab_name, $lab_address"),
default_mime_type="text/x-html",
output_mime_type="text/x-html",
allow_file_upload=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
This report was sent to the following contacts:
</p>

$recipients
<p>$recipients</p>

<p i18n:translate="">
With best regards
</p>
<tal:laboratory tal:replace="python:laboratory.getName() or 'SENAITE LIMS'"/>

<p>$lab_name</p>

<p i18n:translate="">
*** This is an automatically generated email, please do not reply to this message. ***
Expand Down
9 changes: 7 additions & 2 deletions src/senaite/core/content/senaitesetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ class ISetupSchema(model.Schema):

directives.widget("email_body_sample_publication", RichTextFieldWidget)
email_body_sample_publication = RichTextField(
title=_(u"Publication Email Text"),
title=_("title_senaitesetup_publication_email_text",
default=u"Publication Email Text"),
description=_(
"The default text that is used for the publication email."),
"description_senaitesetup_publication_email_text",
default=u"Set the email body text to be used by default "
"when sending out result reports to the selected recipients. "
"You can use reserved keywords: "
"$client_name, $recipients, $lab_name, $lab_address"),
defaultFactory=default_email_body_sample_publication,
required=False,
)
Expand Down

0 comments on commit 5609a01

Please sign in to comment.