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 %} +
Name: {{event.name|striptags}}
+Date: {{event.local_start_time}}
+Recurring: {% for rule in event.series.recurrences.rrules %}{{rule.to_text|capfirst}}{% endfor %}
+ +