fix speaker & volunteer mails

This commit is contained in:
Élie Bouttier 2017-12-17 13:57:32 +01:00
parent 1c39923fd7
commit 0434a4514d
3 changed files with 27 additions and 15 deletions

View File

@ -59,12 +59,18 @@ def send_message_notifications(sender, instance, **kwargs):
else:
user = thread.volunteer
dests = [ (user, user.name, user.email) ]
if message.subject:
user_subject = None
staff_subject = None
else:
user_subject = _('[%(conference)s] Message from the staff') % {'conference': str(conf)}
staff_subject = _('[%(conference)s] Conversation with %(user)s') % {'conference': str(conf), 'user': str(user)}
if author == user: # message from the user, notify the staff
message.send_notification(sender=sender, dests=staff_dests, reply_to=reply_to, message_id=message_id, reference=reference)
message.send_notification(sender=sender, dests=staff_dests, reply_to=reply_to, message_id=message_id, reference=reference, subject=staff_subject)
else: # message to the user, notify the user, and the staff if the message is not a conference notification
message.send_notification(sender=sender, dests=dests, reply_to=reply_to, message_id=message_id, reference=reference)
message.send_notification(sender=sender, dests=dests, reply_to=reply_to, message_id=message_id, reference=reference, subject=user_subject)
if author != conf:
message.send_notification(sender=sender, dests=staff_dests, reply_to=reply_to, message_id=message_id, reference=reference)
message.send_notification(sender=sender, dests=staff_dests, reply_to=reply_to, message_id=message_id, reference=reference, subject=staff_subject)
elif hasattr(thread, 'talk'):
message.send_notification(sender=sender, dests=staff_dests,
reply_to=reply_to, message_id=message_id, reference=reference)

View File

@ -213,11 +213,14 @@ def volunteer_details(request, volunteer_id):
volunteer = get_object_or_404(Volunteer, site=request.conference.site, pk=volunteer_id)
message_form = MessageForm(request.POST or None)
if request.method == 'POST' and message_form.is_valid():
message = message_form.save(commit=False)
message.author = request.user
message.from_email = request.user.email
message.thread = volunteer.conversation
message.save()
in_reply_to = volunteer.conversation.message_set.last()
send_message(
thread=volunteer.conversation,
author=request.user,
subject='',
content=message_form.cleaned_data['content'],
in_reply_to=in_reply_to,
)
messages.success(request, _('Message sent!'))
return redirect(reverse('volunteer-details', args=[volunteer.pk]))
return render(request, 'cfp/staff/volunteer_details.html', {
@ -958,11 +961,14 @@ def participant_details(request, participant_id):
participant = get_object_or_404(Participant, pk=participant_id, site=request.conference.site)
message_form = MessageForm(request.POST or None)
if request.method == 'POST' and message_form.is_valid():
message = message_form.save(commit=False)
message.author = request.user
message.from_email = request.user.email
message.thread = participant.conversation
message.save()
in_reply_to = participant.conversation.message_set.last()
send_message(
thread=participant.conversation,
author=request.user,
subject='',
content=message_form.cleaned_data['content'],
in_reply_to=in_reply_to,
)
messages.success(request, _('Message sent!'))
return redirect(reverse('participant-details', args=[participant.pk]))
return render(request, 'cfp/staff/participant_details.html', {

View File

@ -68,7 +68,7 @@ class Message(models.Model):
class Meta:
ordering = ['created']
def send_notification(self, sender, dests, reply_to=None, message_id=None, reference=None, footer=None):
def send_notification(self, sender, dests, reply_to=None, message_id=None, reference=None, footer=None, subject=None):
messages = []
for dest, dest_name, dest_email in dests:
dest_type = ContentType.objects.get_for_model(dest)
@ -92,7 +92,7 @@ class Message(models.Model):
if footer is not None:
body += footer
messages.append(EmailMessage(
subject=self.subject,
subject=subject or self.subject,
body=body,
from_email='%s <%s>' % sender,
to=['%s <%s>' % (dest_name, dest_email)],