fix speaker & volunteer mails
This commit is contained in:
parent
1c39923fd7
commit
0434a4514d
|
@ -59,12 +59,18 @@ def send_message_notifications(sender, instance, **kwargs):
|
||||||
else:
|
else:
|
||||||
user = thread.volunteer
|
user = thread.volunteer
|
||||||
dests = [ (user, user.name, user.email) ]
|
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
|
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
|
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:
|
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'):
|
elif hasattr(thread, 'talk'):
|
||||||
message.send_notification(sender=sender, dests=staff_dests,
|
message.send_notification(sender=sender, dests=staff_dests,
|
||||||
reply_to=reply_to, message_id=message_id, reference=reference)
|
reply_to=reply_to, message_id=message_id, reference=reference)
|
||||||
|
|
26
cfp/views.py
26
cfp/views.py
|
@ -213,11 +213,14 @@ def volunteer_details(request, volunteer_id):
|
||||||
volunteer = get_object_or_404(Volunteer, site=request.conference.site, pk=volunteer_id)
|
volunteer = get_object_or_404(Volunteer, site=request.conference.site, pk=volunteer_id)
|
||||||
message_form = MessageForm(request.POST or None)
|
message_form = MessageForm(request.POST or None)
|
||||||
if request.method == 'POST' and message_form.is_valid():
|
if request.method == 'POST' and message_form.is_valid():
|
||||||
message = message_form.save(commit=False)
|
in_reply_to = volunteer.conversation.message_set.last()
|
||||||
message.author = request.user
|
send_message(
|
||||||
message.from_email = request.user.email
|
thread=volunteer.conversation,
|
||||||
message.thread = volunteer.conversation
|
author=request.user,
|
||||||
message.save()
|
subject='',
|
||||||
|
content=message_form.cleaned_data['content'],
|
||||||
|
in_reply_to=in_reply_to,
|
||||||
|
)
|
||||||
messages.success(request, _('Message sent!'))
|
messages.success(request, _('Message sent!'))
|
||||||
return redirect(reverse('volunteer-details', args=[volunteer.pk]))
|
return redirect(reverse('volunteer-details', args=[volunteer.pk]))
|
||||||
return render(request, 'cfp/staff/volunteer_details.html', {
|
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)
|
participant = get_object_or_404(Participant, pk=participant_id, site=request.conference.site)
|
||||||
message_form = MessageForm(request.POST or None)
|
message_form = MessageForm(request.POST or None)
|
||||||
if request.method == 'POST' and message_form.is_valid():
|
if request.method == 'POST' and message_form.is_valid():
|
||||||
message = message_form.save(commit=False)
|
in_reply_to = participant.conversation.message_set.last()
|
||||||
message.author = request.user
|
send_message(
|
||||||
message.from_email = request.user.email
|
thread=participant.conversation,
|
||||||
message.thread = participant.conversation
|
author=request.user,
|
||||||
message.save()
|
subject='',
|
||||||
|
content=message_form.cleaned_data['content'],
|
||||||
|
in_reply_to=in_reply_to,
|
||||||
|
)
|
||||||
messages.success(request, _('Message sent!'))
|
messages.success(request, _('Message sent!'))
|
||||||
return redirect(reverse('participant-details', args=[participant.pk]))
|
return redirect(reverse('participant-details', args=[participant.pk]))
|
||||||
return render(request, 'cfp/staff/participant_details.html', {
|
return render(request, 'cfp/staff/participant_details.html', {
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Message(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['created']
|
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 = []
|
messages = []
|
||||||
for dest, dest_name, dest_email in dests:
|
for dest, dest_name, dest_email in dests:
|
||||||
dest_type = ContentType.objects.get_for_model(dest)
|
dest_type = ContentType.objects.get_for_model(dest)
|
||||||
|
@ -92,7 +92,7 @@ class Message(models.Model):
|
||||||
if footer is not None:
|
if footer is not None:
|
||||||
body += footer
|
body += footer
|
||||||
messages.append(EmailMessage(
|
messages.append(EmailMessage(
|
||||||
subject=self.subject,
|
subject=subject or self.subject,
|
||||||
body=body,
|
body=body,
|
||||||
from_email='%s <%s>' % sender,
|
from_email='%s <%s>' % sender,
|
||||||
to=['%s <%s>' % (dest_name, dest_email)],
|
to=['%s <%s>' % (dest_name, dest_email)],
|
||||||
|
|
Loading…
Reference in New Issue