From 2f6b56384193d15302e8985ff3fe48e49ab47654 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Sat, 12 May 2018 23:19:58 -0400 Subject: [PATCH] Email event hosts when the next event in their series has been created --- .../commands/create_next_in_series.py | 20 --------- events/models/events.py | 1 + .../commands/create_next_in_series.py | 44 +++++++++++++++++++ .../get_together/emails/attendee_invite.txt | 1 + .../get_together/emails/event_comment.txt | 1 + .../emails/event_from_series.html | 13 ++++++ .../get_together/emails/event_from_series.txt | 11 +++++ .../get_together/emails/member_contact.txt | 1 + .../get_together/emails/member_invite.txt | 1 + .../get_together/emails/reminder.txt | 1 + 10 files changed, 74 insertions(+), 20 deletions(-) delete mode 100644 events/management/commands/create_next_in_series.py create mode 100644 get_together/management/commands/create_next_in_series.py create mode 100644 get_together/templates/get_together/emails/event_from_series.html create mode 100644 get_together/templates/get_together/emails/event_from_series.txt diff --git a/events/management/commands/create_next_in_series.py b/events/management/commands/create_next_in_series.py deleted file mode 100644 index 86164b5..0000000 --- a/events/management/commands/create_next_in_series.py +++ /dev/null @@ -1,20 +0,0 @@ -from django.core.management.base import BaseCommand, CommandError -from django.conf import settings -from django.contrib.sites.models import Site -from django.utils import timezone - -from events.models import Event, EventSeries - -import time -import datetime - -class Command(BaseCommand): - help = "Generates the next event for any series that needs one" - - def handle(self, *args, **options): - needs_update = EventSeries.objects.filter(last_time__lte=timezone.now()) - - for series in needs_update: - next_event = series.create_next_in_series() - if next_event is not None: - print("Created new event: %s" % next_event) diff --git a/events/models/events.py b/events/models/events.py index d564aef..2115cea 100644 --- a/events/models/events.py +++ b/events/models/events.py @@ -349,6 +349,7 @@ class EventSeries(models.Model): created_by=self.created_by, ) next_event.save() + Attendee.objects.create(event=next_event, user=self.created_by, role=Attendee.HOST, status=Attendee.YES) self.last_time = next_event.start_time self.save() return next_event diff --git a/get_together/management/commands/create_next_in_series.py b/get_together/management/commands/create_next_in_series.py new file mode 100644 index 0000000..6ccff17 --- /dev/null +++ b/get_together/management/commands/create_next_in_series.py @@ -0,0 +1,44 @@ +from django.core.management.base import BaseCommand, CommandError +from django.conf import settings +from django.contrib.sites.models import Site +from django.utils import timezone +from django.core.mail import send_mail +from django.template.loader import get_template, render_to_string + +from events.models import Event, EventSeries, Attendee + +import time +import datetime + +class Command(BaseCommand): + help = "Generates the next event for any series that needs one" + + def handle(self, *args, **options): + needs_update = EventSeries.objects.filter(last_time__lte=timezone.now()) + + for series in needs_update: + next_event = series.create_next_in_series() + if next_event is not None: + print("Created new event: %s" % next_event) + email_host_new_event(next_event) + + +def email_host_new_event(event): + context = { + 'event': event, + 'site': Site.objects.get(id=1), + } + email_subject = '[GetTogether] New event: %s' % event.name + email_body_text = render_to_string('get_together/emails/event_from_series.txt', context) + email_body_html = render_to_string('get_together/emails/event_from_series.html', context) + email_from = getattr(settings, 'DEFAULT_FROM_EMAIL', 'noreply@gettogether.community') + + for attendee in Attendee.objects.filter(event=event, role=Attendee.HOST, user__user__account__is_email_confirmed=True): + send_mail( + from_email=email_from, + html_message=email_body_html, + message=email_body_text, + recipient_list=[attendee.user.user.email], + subject=email_subject, + fail_silently=True, + ) \ No newline at end of file diff --git a/get_together/templates/get_together/emails/attendee_invite.txt b/get_together/templates/get_together/emails/attendee_invite.txt index e14a1a3..70a468e 100644 --- a/get_together/templates/get_together/emails/attendee_invite.txt +++ b/get_together/templates/get_together/emails/attendee_invite.txt @@ -1,3 +1,4 @@ +{% extends 'get_together/emails/base.txt' %} {% block content %} == You've been invited to attend {{event.name|striptags}} == diff --git a/get_together/templates/get_together/emails/event_comment.txt b/get_together/templates/get_together/emails/event_comment.txt index 433d7b8..d1654cb 100644 --- a/get_together/templates/get_together/emails/event_comment.txt +++ b/get_together/templates/get_together/emails/event_comment.txt @@ -1,3 +1,4 @@ +{% extends 'get_together/emails/base.txt' %} {% block content %} == Comment on {{comment.event.name|striptags}} == diff --git a/get_together/templates/get_together/emails/event_from_series.html b/get_together/templates/get_together/emails/event_from_series.html new file mode 100644 index 0000000..5af6a9d --- /dev/null +++ b/get_together/templates/get_together/emails/event_from_series.html @@ -0,0 +1,13 @@ +{% extends "get_together/emails/base.html" %} + +{% block content %} +

Your new event is ready

+ +

Name: {{event.name|striptags}}

+

Date: {{event.local_start_time}}

+

Recurring: {% for rule in event.series.recurrences.rrules %}{{rule.to_text|capfirst}}{% endfor %}

+ +
+View your event. +

+{% endblock %} diff --git a/get_together/templates/get_together/emails/event_from_series.txt b/get_together/templates/get_together/emails/event_from_series.txt new file mode 100644 index 0000000..e587f41 --- /dev/null +++ b/get_together/templates/get_together/emails/event_from_series.txt @@ -0,0 +1,11 @@ +{% extends 'get_together/emails/base.txt' %} +{% block content %} +== Your new event is ready == + +Name: {{event.name|striptags}} +Date: {{event.local_start_time}} +Recurring: {% for rule in event.series.recurrences.rrules %}{{rule.to_text|capfirst}}{% endfor %} + +Click here to view your event: {{event.get_full_url}} + +{% endblock %} diff --git a/get_together/templates/get_together/emails/member_contact.txt b/get_together/templates/get_together/emails/member_contact.txt index 022e043..6f3be63 100644 --- a/get_together/templates/get_together/emails/member_contact.txt +++ b/get_together/templates/get_together/emails/member_contact.txt @@ -1,3 +1,4 @@ +{% extends 'get_together/emails/base.txt' %} {% block content %} == Message from {{team.name}} == diff --git a/get_together/templates/get_together/emails/member_invite.txt b/get_together/templates/get_together/emails/member_invite.txt index 352a836..17ce15a 100644 --- a/get_together/templates/get_together/emails/member_invite.txt +++ b/get_together/templates/get_together/emails/member_invite.txt @@ -1,3 +1,4 @@ +{% extends 'get_together/emails/base.txt' %} {% block content %} == You've been invited to join {{team.name}} == diff --git a/get_together/templates/get_together/emails/reminder.txt b/get_together/templates/get_together/emails/reminder.txt index d4a3bf2..6c84b13 100644 --- a/get_together/templates/get_together/emails/reminder.txt +++ b/get_together/templates/get_together/emails/reminder.txt @@ -1,3 +1,4 @@ +{% extends 'get_together/emails/base.txt' %} {% block content %} == Event Reminder Notification ==