summaryrefslogtreecommitdiff
path: root/app/lttr/management/commands/send_newsletter.py
diff options
context:
space:
mode:
authorlxf <sng@luxagraf.net>2022-05-14 16:38:07 -0400
committerlxf <sng@luxagraf.net>2022-05-14 16:38:07 -0400
commitbb3973ffb714c932e9ec6dd6a751228dc71fe1d3 (patch)
tree6fa32f9392ad2ec32271349b86a4c1388fd6ba95 /app/lttr/management/commands/send_newsletter.py
initial commit
Diffstat (limited to 'app/lttr/management/commands/send_newsletter.py')
-rw-r--r--app/lttr/management/commands/send_newsletter.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/lttr/management/commands/send_newsletter.py b/app/lttr/management/commands/send_newsletter.py
new file mode 100644
index 0000000..0f36183
--- /dev/null
+++ b/app/lttr/management/commands/send_newsletter.py
@@ -0,0 +1,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')