Skip to content

Commit 5609a01

Browse files
authored
Improve default body text for email publication to allow translations (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
1 parent ab07811 commit 5609a01

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

src/bika/lims/browser/publish/emailview.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ def email_body(self):
303303
body = setup.getEmailBodySamplePublication()
304304
template_context = {
305305
"client_name": self.client_name,
306+
"lab_name": self.lab_name,
307+
"lab_address": self.lab_address,
306308
}
307309
rendered_body = self.render_email_template(
308310
body, template_context=template_context)
@@ -361,6 +363,18 @@ def client_name(self):
361363
"""
362364
return safe_unicode(self.context.Title())
363365

366+
@property
367+
def lab_address(self):
368+
"""Returns the laboratory print address
369+
"""
370+
return "<br/>".join(self.laboratory.getPrintAddress())
371+
372+
@property
373+
def lab_name(self):
374+
"""Returns the laboratory name
375+
"""
376+
return self.laboratory.getName()
377+
364378
@property
365379
def exit_url(self):
366380
"""Exit URL for redirect
@@ -484,7 +498,7 @@ def render_email_template(self, template, template_context=None):
484498
"""
485499

486500
# allow to add translation for initial template
487-
template = self.context.translate(template)
501+
template = self.context.translate(_(template))
488502
recipients = self.email_recipients_and_responsibles
489503
if template_context is None:
490504
template_context = {

src/bika/lims/content/bikasetup.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,15 @@ def getCounterTypes(self, instance=None):
625625
# Needed to fetch the default value from the registry
626626
edit_accessor="getEmailBodySamplePublication",
627627
widget=RichWidget(
628-
label=_("Email body for Sample publication notifications"),
628+
label=_(
629+
"label_bikasetup_email_body_sample_publication",
630+
"Email body for Sample publication notifications"),
629631
description=_(
630-
"The default text that is used for the publication email. "
631-
" sending publication reports."),
632+
"description_bikasetup_email_body_sample_publication",
633+
default="Set the email body text to be used by default when "
634+
"sending out result reports to the selected recipients. "
635+
"You can use reserved keywords: "
636+
"$client_name, $recipients, $lab_name, $lab_address"),
632637
default_mime_type="text/x-html",
633638
output_mime_type="text/x-html",
634639
allow_file_upload=False,

src/senaite/core/browser/setup/templates/email_body_sample_publication.pt

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
This report was sent to the following contacts:
1616
</p>
1717

18-
$recipients
18+
<p>$recipients</p>
1919

2020
<p i18n:translate="">
2121
With best regards
2222
</p>
23-
<tal:laboratory tal:replace="python:laboratory.getName() or 'SENAITE LIMS'"/>
23+
24+
<p>$lab_name</p>
2425

2526
<p i18n:translate="">
2627
*** This is an automatically generated email, please do not reply to this message. ***

src/senaite/core/content/senaitesetup.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ class ISetupSchema(model.Schema):
4040

4141
directives.widget("email_body_sample_publication", RichTextFieldWidget)
4242
email_body_sample_publication = RichTextField(
43-
title=_(u"Publication Email Text"),
43+
title=_("title_senaitesetup_publication_email_text",
44+
default=u"Publication Email Text"),
4445
description=_(
45-
"The default text that is used for the publication email."),
46+
"description_senaitesetup_publication_email_text",
47+
default=u"Set the email body text to be used by default "
48+
"when sending out result reports to the selected recipients. "
49+
"You can use reserved keywords: "
50+
"$client_name, $recipients, $lab_name, $lab_address"),
4651
defaultFactory=default_email_body_sample_publication,
4752
required=False,
4853
)

0 commit comments

Comments
 (0)