blob: 0f3618365d95e0122eba325b56d40c86f4a01ea4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
"""Command for sending the newsletter"""
from django.conf import settings
from django.utils.translation import activate
from django.core.management.base import NoArgsCommand
from lttr.mailer import Mailer
from lttr.models import NewsletterMailing
class Command(NoArgsCommand):
"""Send the newsletter in queue"""
help = 'Send the newsletter in queue'
def handle_noargs(self, **options):
verbose = int(options['verbosity'])
if verbose:
print('Starting sending newsletters...')
activate(settings.LANGUAGE_CODE)
for newsletter in NewsletterMailing.objects.exclude(
status=Newsletter.DRAFT).exclude(status=Newsletter.SENT):
mailer = Mailer(newsletter, verbose=verbose)
if mailer.can_send:
if verbose:
print('Start emailing %s' % newsletter.title)
mailer.run()
if verbose:
print('End session sending')
|