Email event hosts when the next event in their series has been created
This commit is contained in:
parent
508080f78e
commit
2f6b563841
10 changed files with 74 additions and 20 deletions
|
@ -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)
|
|
@ -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
|
||||
|
|
44
get_together/management/commands/create_next_in_series.py
Normal file
44
get_together/management/commands/create_next_in_series.py
Normal file
|
@ -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,
|
||||
)
|
|
@ -1,3 +1,4 @@
|
|||
{% extends 'get_together/emails/base.txt' %}
|
||||
{% block content %}
|
||||
== You've been invited to attend {{event.name|striptags}} ==
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{% extends 'get_together/emails/base.txt' %}
|
||||
{% block content %}
|
||||
== Comment on {{comment.event.name|striptags}} ==
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "get_together/emails/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h3>Your new event is ready</h3>
|
||||
|
||||
<p><b>Name:</b> {{event.name|striptags}}</p>
|
||||
<p><b>Date:</b> {{event.local_start_time}}</p>
|
||||
<p><b>Recurring:</b> {% for rule in event.series.recurrences.rrules %}{{rule.to_text|capfirst}}{% endfor %}</p>
|
||||
|
||||
<br>
|
||||
<a href="{{event.get_full_url}}" title="{{ event.name|striptags }} page.">View your event.</a>
|
||||
</p>
|
||||
{% endblock %}
|
|
@ -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 %}
|
|
@ -1,3 +1,4 @@
|
|||
{% extends 'get_together/emails/base.txt' %}
|
||||
{% block content %}
|
||||
== Message from {{team.name}} ==
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{% extends 'get_together/emails/base.txt' %}
|
||||
{% block content %}
|
||||
== You've been invited to join {{team.name}} ==
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
{% extends 'get_together/emails/base.txt' %}
|
||||
{% block content %}
|
||||
== Event Reminder Notification ==
|
||||
|
||||
|
|
Loading…
Reference in a new issue