SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit b234b7e5 authored by George Katsikas's avatar George Katsikas :goat:
Browse files

fix greeting & allow html tags in college mail

parent d056895e
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ __license__ = "AGPL v3" ...@@ -3,6 +3,7 @@ __license__ = "AGPL v3"
import datetime import datetime
import bleach
from django.db.models import Q from django.db.models import Q
import pyotp import pyotp
import re import re
...@@ -23,6 +24,8 @@ from crispy_forms.helper import FormHelper ...@@ -23,6 +24,8 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Field, ButtonHolder, Submit from crispy_forms.layout import Layout, Div, Field, ButtonHolder, Submit
from dal import autocomplete from dal import autocomplete
from markup.constants import BLEACH_ALLOWED_ATTRIBUTES, BLEACH_ALLOWED_TAGS
from .behaviors import orcid_validator from .behaviors import orcid_validator
from .constants import ( from .constants import (
NEWLY_REGISTERED, NEWLY_REGISTERED,
...@@ -1075,23 +1078,24 @@ class EmailUsersForm(forms.Form): ...@@ -1075,23 +1078,24 @@ class EmailUsersForm(forms.Form):
email_text = "" email_text = ""
email_text_html = "" email_text_html = ""
if self.cleaned_data["personalize"]: if self.cleaned_data["personalize"]:
email_text = ( email_text = f"Dear {user.contributor.profile.formal_name}, \n\n"
"Dear " email_text_html = "Dear {{ formal_name }},<br/>"
+ user.contributor.profile.get_title_display()
+ " " bleached_email_text = bleach.clean(
+ user.last_name self.cleaned_data["email_text"],
+ ", \n\n" tags=BLEACH_ALLOWED_TAGS,
) attributes=BLEACH_ALLOWED_ATTRIBUTES,
email_text_html = "Dear {{ title }} {{ last_name }},<br/>" )
email_text += self.cleaned_data["email_text"] email_text += bleached_email_text
email_text_html += "{{ email_text|linebreaks }}" email_text_html += "{{ bleached_email_text|safe|linebreaksbr }}"
email_context = { email_context = {
"title": user.contributor.profile.get_title_display(), "formal_name": user.contributor.profile.formal_name,
"last_name": user.last_name, "bleached_email_text": bleached_email_text,
"email_text": self.cleaned_data["email_text"],
} }
html_template = Template(email_text_html) html_template = Template(email_text_html)
html_version = html_template.render(Context(email_context)) html_version = html_template.render(Context(email_context))
message = mail.EmailMultiAlternatives( message = mail.EmailMultiAlternatives(
self.cleaned_data["email_subject"], self.cleaned_data["email_subject"],
email_text, email_text,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment