From bebb84680a9b6ced73ff39c8b1d5f464aa03c139 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Thu, 17 May 2018 21:29:04 -0400 Subject: [PATCH] Send talk proposal and acceptance emails. Fixed #83 --- .../emails/events/talk_acceptance.html | 16 ++++ .../emails/events/talk_acceptance.txt | 15 ++++ .../emails/events/talk_proposed.html | 16 ++++ .../emails/events/talk_proposed.txt | 15 ++++ get_together/views/speakers.py | 83 ++++++++++++++++++- 5 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 get_together/templates/get_together/emails/events/talk_acceptance.html create mode 100644 get_together/templates/get_together/emails/events/talk_acceptance.txt create mode 100644 get_together/templates/get_together/emails/events/talk_proposed.html create mode 100644 get_together/templates/get_together/emails/events/talk_proposed.txt diff --git a/get_together/templates/get_together/emails/events/talk_acceptance.html b/get_together/templates/get_together/emails/events/talk_acceptance.html new file mode 100644 index 0000000..81d17f3 --- /dev/null +++ b/get_together/templates/get_together/emails/events/talk_acceptance.html @@ -0,0 +1,16 @@ +{% extends "get_together/emails/base.html" %} + +{% block content %} +

You proposed a talk for {{event.name|striptags}}

+ +{% if proposal.status == proposal.ACCEPTED %} +Congratulations! Your submitted talk, {{proposal.talk.title}}, has been accepted by the event hosts. +{% elif proposal.status == proposal.DECLINED %} +Unfortunately your submitted talk, {{proposal.talk.title}}, was declined by the event hosts. +{% else %} +Your submitted talk, {{proposal.talk.title}}, is currently being reviewed by the event hosts. +{% endif %} + +View this event. +

+{% endblock %} diff --git a/get_together/templates/get_together/emails/events/talk_acceptance.txt b/get_together/templates/get_together/emails/events/talk_acceptance.txt new file mode 100644 index 0000000..4a2b732 --- /dev/null +++ b/get_together/templates/get_together/emails/events/talk_acceptance.txt @@ -0,0 +1,15 @@ +{% extends 'get_together/emails/base.txt' %} +{% block content %} +== You proposed a talk for {{event.name|striptags}} == + +{% if proposal.status == proposal.ACCEPTED %} +Congratulations! Your submitted talk, {{proposal.talk.title}}, has been accepted by the event hosts. +{% elif proposal.status == proposal.DECLINED %} +Unfortunately your submitted talk, {{proposal.talk.title}}, was declined by the event hosts. +{% else %} +Your submitted talk, {{proposal.talk.title}}, is currently being reviewed by the event hosts. +{% endif %} + +Click here to view this event: {{event.get_full_url}} + +{% endblock %} diff --git a/get_together/templates/get_together/emails/events/talk_proposed.html b/get_together/templates/get_together/emails/events/talk_proposed.html new file mode 100644 index 0000000..ea7a55b --- /dev/null +++ b/get_together/templates/get_together/emails/events/talk_proposed.html @@ -0,0 +1,16 @@ +{% extends "get_together/emails/base.html" %} + +{% block content %} +

Talk proposal for {{event.name|striptags}}

+ +

By: {{ proposal.talk.speaker.user }}, {{ proposal.talk.speaker.title }}

+ +

{{ proposal.talk.title }}

+

{{proposal.talk.abstract}}

+ +

About {{ proposal.talk.speaker.user }}

+

{{proposal.talk.speaker.bio}}

+ +Review this proposal. +

+{% endblock %} diff --git a/get_together/templates/get_together/emails/events/talk_proposed.txt b/get_together/templates/get_together/emails/events/talk_proposed.txt new file mode 100644 index 0000000..a5feca2 --- /dev/null +++ b/get_together/templates/get_together/emails/events/talk_proposed.txt @@ -0,0 +1,15 @@ +{% extends 'get_together/emails/base.txt' %} +{% block content %} +== Talk proposal for {{event.name|striptags}} == + +By {{ proposal.talk.speaker.user }}, {{ proposal.talk.speaker.title }} + +=== {{ proposal.talk.title }} === +{{proposal.talk.abstract}} + +=== About {{ proposal.talk.speaker.user }} === +{{proposal.talk.speaker.bio}} + +Click here to review this proposal: https://{{site.domain}}{% url 'schedule-event-talks' event.id %} + +{% endblock %} diff --git a/get_together/views/speakers.py b/get_together/views/speakers.py index a7f6ab8..96f7d3d 100644 --- a/get_together/views/speakers.py +++ b/get_together/views/speakers.py @@ -1,10 +1,12 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.safestring import mark_safe from django.contrib import messages -from django.contrib.auth import logout as logout_user +from django.contrib.sites.models import Site from django.shortcuts import render, redirect, get_object_or_404 -from django.http import HttpResponse, JsonResponse -from django.core.exceptions import ObjectDoesNotExist +from django.contrib.auth.decorators import login_required +from django.core.mail import send_mail +from django.template.loader import get_template, render_to_string +from django.conf import settings from events.models.profiles import UserProfile from events.forms import ( @@ -15,6 +17,7 @@ from events.forms import ( SchedulePresentationForm, ) + from events.models.events import Event from events.models.speakers import Speaker, Talk, Presentation, SpeakerRequest import datetime @@ -23,6 +26,7 @@ import simplejson from .teams import * from .events import * + @login_required def list_user_talks(request): profile = request.user.profile @@ -34,6 +38,7 @@ def list_user_talks(request): } return render(request, 'get_together/speakers/list_user_talks.html', context) + def show_speaker(request, speaker_id): speaker = get_object_or_404(Speaker, id=speaker_id) @@ -44,6 +49,7 @@ def show_speaker(request, speaker_id): } return render(request, 'get_together/speakers/show_speaker.html', context) + def add_speaker(request): new_speaker = Speaker(user=request.user.profile) if request.method == 'GET': @@ -66,6 +72,7 @@ def add_speaker(request): return render(request, 'get_together/speakers/create_speaker.html', context) return redirect('home') + def edit_speaker(request, speaker_id): speaker = get_object_or_404(Speaker, id=speaker_id) if request.method == 'GET': @@ -88,6 +95,7 @@ def edit_speaker(request, speaker_id): return render(request, 'get_together/speakers/edit_speaker.html', context) return redirect('home') + def delete_speaker(request, speaker_id): speaker = get_object_or_404(Speaker, id=speaker_id) if not speaker.user == request.user.profile: @@ -116,6 +124,7 @@ def delete_speaker(request, speaker_id): else: return redirect('home') + def show_talk(request, talk_id): talk = get_object_or_404(Talk, id=talk_id) presentations = Presentation.objects.filter(talk=talk, status=Presentation.ACCEPTED).order_by('-event__start_time') @@ -125,6 +134,7 @@ def show_talk(request, talk_id): } return render(request, 'get_together/speakers/show_talk.html', context) + def add_talk(request): if Speaker.objects.filter(user=request.user.profile).count() < 1: messages.add_message(request, messages.WARNING, message=_('You must create a new Speaker profile before you can add a talk')) @@ -164,6 +174,7 @@ def add_talk(request): return render(request, 'get_together/speakers/create_talk.html', context) return redirect('home') + def edit_talk(request, talk_id): talk = get_object_or_404(Talk, id=talk_id) if not talk.speaker.user == request.user.profile: @@ -192,6 +203,7 @@ def edit_talk(request, talk_id): return render(request, 'get_together/speakers/edit_talk.html', context) return redirect('home') + def delete_talk(request, talk_id): talk = get_object_or_404(Talk, id=talk_id) if not talk.speaker.user == request.user.profile: @@ -220,6 +232,7 @@ def delete_talk(request, talk_id): else: return redirect('home') + @login_required def propose_event_talk(request, event_id): event = get_object_or_404(Event, id=event_id) @@ -252,11 +265,44 @@ def propose_event_talk(request, event_id): start_time=event.local_start_time, created_by=request.user.profile, ) + send_talk_proposed_emails(new_proposal) messages.add_message(request, messages.SUCCESS, message=_('Your talk has been submitted to the event organizer.')) return redirect(event.get_absolute_url()) else: redirect('home') + +def send_talk_proposed_emails(proposal): + context = { + 'proposal': proposal, + 'event': proposal.event, + 'talk': proposal.talk, + 'site': Site.objects.get(id=1), + } + email_subject = '[GetTogether] Talk proposal for %s' % proposal.event.name + email_body_text = render_to_string('get_together/emails/events/talk_proposed.txt', context) + email_body_html = render_to_string('get_together/emails/events/talk_proposed.html', context) + email_from = getattr(settings, 'DEFAULT_FROM_EMAIL', 'noreply@gettogether.community') + + for host in Attendee.objects.filter(event=proposal.event, role=Attendee.HOST, user__user__account__is_email_confirmed=True): + success = send_mail( + from_email=email_from, + html_message=email_body_html, + message=email_body_text, + recipient_list=[host.user.user.email], + subject=email_subject, + fail_silently=True, + ) + EmailRecord.objects.create( + sender=proposal.talk.speaker.user.user, + recipient=host.user.user, + email=host.user.user.email, + subject=email_subject, + body=email_body_text, + ok=success + ) + + def schedule_event_talks(request, event_id): event = get_object_or_404(Event, id=event_id) if not request.user.profile.can_edit_event(event): @@ -275,6 +321,7 @@ def schedule_event_talks(request, event_id): elif request.POST.get('action') == 'propose': presentation.status = Presentation.PROPOSED presentation.save() + send_talk_acceptance_emails(presentation, request.user) context = { 'event': event, @@ -285,3 +332,33 @@ def schedule_event_talks(request, event_id): } return render(request, 'get_together/events/schedule_event_talks.html', context) + +def send_talk_acceptance_emails(proposal, reviewer): + context = { + 'proposal': proposal, + 'event': proposal.event, + 'talk': proposal.talk, + 'reviewer': reviewer, + 'site': Site.objects.get(id=1), + } + email_subject = '[GetTogether] About your talk proposal %s' % proposal.event.name + email_body_text = render_to_string('get_together/emails/events/talk_acceptance.txt', context) + email_body_html = render_to_string('get_together/emails/events/talk_acceptance.html', context) + email_from = getattr(settings, 'DEFAULT_FROM_EMAIL', 'noreply@gettogether.community') + + success = send_mail( + from_email=email_from, + html_message=email_body_html, + message=email_body_text, + recipient_list=[proposal.talk.speaker.user.user.email], + subject=email_subject, + fail_silently=True, + ) + EmailRecord.objects.create( + sender=reviewer, + recipient=proposal.talk.speaker.user.user, + email=proposal.talk.speaker.user.user.email, + subject=email_subject, + body=email_body_text, + ok=success + )