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") @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 message = instance
thread = message.thread thread = message.thread
first_message = thread.message_set.first() 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} 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} 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 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, message.send_notification(subject=subject_prefix+participant_subject, sender=sender, dests=participant_dests,
reply_to=reply_to, message_id=message_id, reference=reference) reply_to=reply_to, message_id=message_id, reference=reference)
else: else:

View File

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