fix sender display name in mail notifications

This commit is contained in:
Élie Bouttier 2017-08-11 22:25:16 +02:00
parent 7dc49d1e2d
commit 5f8b92c0aa
2 changed files with 6 additions and 6 deletions

View File

@ -51,7 +51,7 @@ def set_message_author(sender, instance, **kwargs):
@receiver(post_save, sender=Message, dispatch_uid="Send message notifications")
def send_message_notification(sender, instance, **kwargs):
def send_message_notifications(sender, instance, **kwargs):
message = instance
thread = message.thread
first_message = thread.message_set.first()
@ -78,7 +78,7 @@ def send_message_notification(sender, instance, **kwargs):
participant_subject = _('[%(prefix)s] Message from the staff') % {'prefix': conf.name}
staff_subject = _('[%(prefix)s] Conversation with %(dest)s') % {'prefix': conf.name, 'dest': participant.name}
if message.from_email == conf.contact_email: # this is a talk notification message
# sent it only the participant
# send it only to the participant
message.send_notification(subject=subject_prefix+participant_subject, sender=sender, dests=participant_dests,
reply_to=reply_to, message_id=message_id, reference=reference)
else:

View File

@ -5,7 +5,7 @@ from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
import hashlib
@ -50,7 +50,6 @@ class Message(models.Model):
for dest_name, dest_email in dests:
correspondent, created = MessageCorrespondent.objects.get_or_create(email=dest_email)
token = self.thread.token + correspondent.token + hexdigest_sha256(settings.SECRET_KEY, self.thread.token, correspondent.token)[:16]
sender_name, sender_email = sender
if reply_to:
reply_to_name, reply_to_email = reply_to
reply_to_list = ['%s <%s>' % (reply_to_name, reply_to_email.format(token=token))]
@ -68,7 +67,7 @@ class Message(models.Model):
messages.append(EmailMessage(
subject=subject,
body=self.content,
from_email='%s <%s>' % (sender_name, sender_email),
from_email='%s <%s>' % sender,
to=['%s <%s>' % (dest_name, dest_email)],
reply_to=reply_to_list,
headers=headers,
@ -79,7 +78,8 @@ class Message(models.Model):
@property
def author_display(self):
if self.author:
if type(self.author) == User:
author_class = ContentType.objects.get_for_model(self.author).model_class()
if author_class == get_user_model():
return self.author.get_full_name()
else:
return str(self.author)