Only send reminders for events starting in the next day, add extra tests, and replace get_absolute_url with get_full_url in email templates

This commit is contained in:
Michael Hall 2018-04-05 22:50:24 -04:00
parent b0b9f273e9
commit 0be7c4b30e
4 changed files with 35 additions and 4 deletions

View file

@ -22,7 +22,8 @@ class Command(BaseCommand):
# Events that start within a day.
query = Q(status=Attendee.YES,
event__start_time__gt=timezone.now())
event__start_time__gt=timezone.now(),
event__start_time__lt=timezone.now()+datetime.timedelta(days=1))
attendees = Attendee.objects.filter(query)
@ -33,7 +34,7 @@ class Command(BaseCommand):
continue
# Skip people who have been reminded in the last day.
if attendee.last_reminded and timezone.now() > attendee.last_reminded - datetime.timedelta(days=1):
if attendee.last_reminded and timezone.now() - datetime.timedelta(days=1) < attendee.last_reminded:
continue
context = {

View file

@ -10,6 +10,6 @@
<strong>Time</strong>: {{event.local_start_time}}<br>
<strong>Location</strong>: {{ event.location|striptags }}<br>
<br>
<a href="{{event.get_absolute_url}}" title="{{ event.name|striptags }} page.">Go to the event page.</a>
<a href="{{event.get_full_url}}" title="{{ event.name|striptags }} page.">Go to the event page.</a>
</p>
{% endblock %}

View file

@ -7,5 +7,5 @@ Name: {{ event.name|striptags }}
Time: {{event.local_start_time}}
Location: {{ event.location|striptags }}
Event page: {{event.get_absolute_url}}
Event page: {{event.get_full_url}}
{% endblock %}

View file

@ -52,3 +52,33 @@ class UpcommingEventReminderTest(TestCase):
call_command('send_event_reminder')
self.assertEquals(len(mail.outbox), 1)
def test_successive_reminders_after_a_day(self):
attendee = mommy.make(Attendee, event=self.event, user=self.userProfile, status=Attendee.YES)
attendee_id = attendee.id
call_command('send_event_reminder')
self.assertEquals(len(mail.outbox), 1)
attendee.last_reminded = timezone.now() - datetime.timedelta(days=2)
attendee.save()
# This should send another email, because the last one was more than a day ago
call_command('send_event_reminder')
self.assertEquals(len(mail.outbox), 2)
def test_reminders_only_for_the_upcoming_day(self):
attendee = mommy.make(Attendee, event=self.event, user=self.userProfile, status=Attendee.YES)
self.event.start_time = timezone.now() + datetime.timedelta(days=2)
self.event.save()
call_command('send_event_reminder')
self.assertEquals(len(mail.outbox), 0)
self.event.start_time = timezone.now() + datetime.timedelta(hours=23)
self.event.save()
call_command('send_event_reminder')
self.assertEquals(len(mail.outbox), 1)