diff --git a/get_together/management/commands/send_event_reminder.py b/get_together/management/commands/send_event_reminder.py index fa3cb0f..0a4c2c7 100644 --- a/get_together/management/commands/send_event_reminder.py +++ b/get_together/management/commands/send_event_reminder.py @@ -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 = { diff --git a/get_together/templates/get_together/emails/reminder.html b/get_together/templates/get_together/emails/reminder.html index dba444d..6a3cea8 100644 --- a/get_together/templates/get_together/emails/reminder.html +++ b/get_together/templates/get_together/emails/reminder.html @@ -10,6 +10,6 @@ Time: {{event.local_start_time}}
Location: {{ event.location|striptags }}

-Go to the event page. +Go to the event page.

{% endblock %} diff --git a/get_together/templates/get_together/emails/reminder.txt b/get_together/templates/get_together/emails/reminder.txt index 8493161..4ac40ea 100644 --- a/get_together/templates/get_together/emails/reminder.txt +++ b/get_together/templates/get_together/emails/reminder.txt @@ -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 %} diff --git a/get_together/tests/event_reminder.py b/get_together/tests/event_reminder.py index acde342..971e032 100644 --- a/get_together/tests/event_reminder.py +++ b/get_together/tests/event_reminder.py @@ -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) + +