def send_email_newsletter_task(newsletters_ids=None, respect_schedule=True): newsletters = None if newsletters_ids: newsletters = Newsletter.objects.filter(id__in=newsletters_ids) send_email_newsletter(newsletters=newsletters, respect_schedule=respect_schedule)
def send_newsletters(self, request, queryset): # This should always be overridden to use a task send_email_newsletter(newsletters=queryset, respect_schedule=False) messages.add_message( request, messages.SUCCESS, 'Sending selected newsletters(s) to the subscribers', )
def test_send_email_newsletter_custom_queryset(self): newsletters = Newsletter.objects.filter(id__in=[ self.released_newsletter_1.id, self.released_newsletter_2.id ]) self.assertFalse(newsletters.filter(is_sent=True).exists()) send_email_newsletter(newsletters=newsletters) self.assertEqual(len(mail.outbox), 10) self.assertEqual(mail.outbox[0].subject, self.released_newsletter_1.subject) self.assertEqual(mail.outbox[5].subject, self.released_newsletter_2.subject) self.assertTrue(newsletters.filter(is_sent=True).exists())
def test_send_email_newsletter_dont_respect_schedule(self): newsletters = Newsletter.objects.filter(id__in=[ self.released_newsletter_1.id, self.released_newsletter_2.id, self.future_scheduled_newsletter.id, ], is_sent=True) self.assertFalse(newsletters.exists()) send_email_newsletter(respect_schedule=False) self.assertEqual(len(mail.outbox), 15) self.assertEqual(mail.outbox[0].subject, self.released_newsletter_1.subject) self.assertEqual(mail.outbox[5].subject, self.released_newsletter_2.subject) self.assertEqual(mail.outbox[10].subject, self.future_scheduled_newsletter.subject) self.assertTrue(newsletters.exists())