From 5f8b92c0aa57efddee300d800761142eb6c530cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Fri, 11 Aug 2017 22:25:16 +0200 Subject: [PATCH] fix sender display name in mail notifications --- cfp/signals.py | 4 ++-- mailing/models.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cfp/signals.py b/cfp/signals.py index 26ff41c..d82cd75 100644 --- a/cfp/signals.py +++ b/cfp/signals.py @@ -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: diff --git a/mailing/models.py b/mailing/models.py index 3f7d575..c26bafe 100644 --- a/mailing/models.py +++ b/mailing/models.py @@ -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)