diff --git a/hypha/apply/activity/adapters/emails.py b/hypha/apply/activity/adapters/emails.py index 6741107a2fe7a5636e0ceb6f1f5c0856a30cae74..d297c06d0aec2c7545710264e693e00d8bed5d98 100644 --- a/hypha/apply/activity/adapters/emails.py +++ b/hypha/apply/activity/adapters/emails.py @@ -14,6 +14,10 @@ from hypha.apply.users.groups import ( STAFF_GROUP_NAME, ) from hypha.apply.users.models import User +from hypha.core.mail import ( + language, + remove_extra_empty_lines, +) from ..options import MESSAGES from ..tasks import send_mail @@ -350,7 +354,11 @@ class EmailAdapter(AdapterBase): ) def render_message(self, template, **kwargs): - return render_to_string(template, kwargs, kwargs['request']) + + with language(settings.LANGUAGE_CODE): + text = render_to_string(template, kwargs, kwargs['request']) + + return remove_extra_empty_lines(text) def send_message(self, message, source, subject, recipient, logs, **kwargs): try: diff --git a/hypha/apply/activity/templates/messages/email/contract_uploaded.html b/hypha/apply/activity/templates/messages/email/contract_uploaded.html index 49fae845e39fd9bdde46f03dd30f71ac6db17318..682a449cee9183f1532adb1459852d4ea1ad683c 100644 --- a/hypha/apply/activity/templates/messages/email/contract_uploaded.html +++ b/hypha/apply/activity/templates/messages/email/contract_uploaded.html @@ -3,34 +3,33 @@ {% load i18n %} {% block salutation %} - {% if request.user != source.user %} - {% blocktrans with name=source.user.get_full_name|default:"applicant" %}Dear {{ name }},{% endblocktrans %} - {% endif %} +{% if request.user != source.user %} +{% blocktrans with name=source.user.get_full_name|default:"applicant" %}Dear {{ name }},{% endblocktrans %} +{% endif %} {% endblock %} {% block content %} - {% trans "A new contract has been added to your Project" %}: +{% trans "A new contract has been added to your Project" %}: - {% trans "Title" %}: {{ source.title }} - {% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "Title" %}: {{ source.title }} +{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} - {% if contract.is_signed %} - {% trans "This contract has already been signed and there is no action for you to take." %} - {% else %} - {% blocktrans %}Please review the contract and sign it before reuploading it to your Project page for the {{ ORG_SHORT_NAME }} Team to approve.{% endblocktrans %} - {% endif %} +{% if contract.is_signed %} +{% trans "This contract has already been signed and there is no action for you to take." %} +{% else %} +{% blocktrans %}Please review the contract and sign it before reuploading it to your Project page for the {{ ORG_SHORT_NAME }} Team to approve.{% endblocktrans %} +{% endif %} {% endblock %} {% block more_info %} - {% if request.user != source.user %} - {% trans "Link to your application" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} - {% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications +{% if request.user != source.user %} +{% trans "Link to your application" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "If you have any questions, please submit them here" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }}#communications - {% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} +{% trans "See our guide for more information" %}: {{ ORG_GUIDE_URL }} - {% blocktrans %}If you have any issues accessing the submission system or other general inquiries, please email us at {{ ORG_EMAIL }}{% endblocktrans %} - {% endif %} +{% blocktrans %}If you have any issues accessing the submission system or other general inquiries, please email us at {{ ORG_EMAIL }}{% endblocktrans %} +{% endif %} {% endblock %} - diff --git a/hypha/apply/activity/templates/messages/email/invoice_status_updated.html b/hypha/apply/activity/templates/messages/email/invoice_status_updated.html index 60322a2b67d33569334c49aaf6d3a9f9a628d10f..70c02082cb30e6f5628b81fe954c993a55af85f2 100644 --- a/hypha/apply/activity/templates/messages/email/invoice_status_updated.html +++ b/hypha/apply/activity/templates/messages/email/invoice_status_updated.html @@ -7,7 +7,7 @@ {% blocktrans with status=invoice.get_status_display %}It is now {{ status }}.{% endblocktrans %} {% if has_changes_requested and invoice.comment %} - {% trans "The staff member left this comment" %}: +{% trans "The staff member left this comment" %}: {{ invoice.comment }} {% endif %} diff --git a/hypha/apply/activity/templates/messages/email/submit_contract_documents.html b/hypha/apply/activity/templates/messages/email/submit_contract_documents.html index 83d6401da513de05045c6f5f1bee7474e2d9b94d..1d2840ebff60386a2d02324e970823bc0d763af1 100644 --- a/hypha/apply/activity/templates/messages/email/submit_contract_documents.html +++ b/hypha/apply/activity/templates/messages/email/submit_contract_documents.html @@ -6,10 +6,10 @@ {% endblock %} {% block content %} - {% trans "A Project's contract is awaiting your review." %} +{% trans "A Project's contract is awaiting your review." %} - {% trans "Title" %}: {{ source.title }} - {% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} +{% trans "Title" %}: {{ source.title }} +{% trans "Link" %}: {{ request.scheme }}://{{ request.get_host }}{{ source.get_absolute_url }} - {% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} +{% blocktrans with lead=source.lead email=source.lead.email %}Please contact {{ lead }} - {{ email }} if you have any questions.{% endblocktrans %} {% endblock %} diff --git a/hypha/core/mail.py b/hypha/core/mail.py index 47f378fae37891b025c9a7183a82d6f55a8ab619..11e432c50aff1a452ef69fdfae1efecbbf91a718 100644 --- a/hypha/core/mail.py +++ b/hypha/core/mail.py @@ -13,7 +13,7 @@ from hypha.core.utils import markdown_to_html logger = logging.getLogger(__name__) -def cleanup_markdown(text): +def remove_extra_empty_lines(text: str) -> str: """Removes extra blank lines and spaces from markdown generated using Django templates. Do this for readably of markdown itself. """ @@ -65,7 +65,7 @@ class MarkdownMail(object): with language(lang): rendered_template = self._render_template(context) - body_txt = cleanup_markdown(rendered_template) + body_txt = remove_extra_empty_lines(rendered_template) body_html = markdown_to_html(rendered_template) email = EmailMultiAlternatives(**kwargs)