From 1495621ef04aa7f86e2020510995d546f9380892 Mon Sep 17 00:00:00 2001 From: Oliver Zander Date: Tue, 19 Aug 2025 16:02:57 +0200 Subject: [PATCH] simplified code --- input/management/commands/sendmails.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/input/management/commands/sendmails.py b/input/management/commands/sendmails.py index 52d48ef..14a732a 100755 --- a/input/management/commands/sendmails.py +++ b/input/management/commands/sendmails.py @@ -1,9 +1,8 @@ from datetime import date, timedelta -import sys -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from django.template.loader import get_template -from django.core.mail import send_mail, BadHeaderError, EmailMessage +from django.core.mail import BadHeaderError from django.core.mail import EmailMultiAlternatives from django.conf import settings @@ -52,7 +51,7 @@ class Command(BaseCommand): # bcc=[SURVEY_EMAIL]) #survey_mail.send(fail_silently=False) except BadHeaderError: - return HttpResponse('Invalid header found.') + return HttpResponse('Invalid header found.') # FIXME HttpResponse??? print(f'send surveylinkemail to {email}...') @@ -296,16 +295,15 @@ class Command(BaseCommand): '''send survey link 2 weeks after mailadresss, mailinglist or businesscards are granted''' lastdate = date.today() - timedelta(days=14) - typefield = ('MAIL','VIS','LIST') - count = 0 - for c in ('Email', 'BusinessCard', 'List'): - # get class via string - supported = getattr(sys.modules[__name__], c).objects.filter(granted=True)\ + models = Email, BusinessCard, List + types = 'MAIL', 'VIS', 'LIST' + + for model, typ in zip(models, types): + supported = model.objects.filter(granted=True)\ .filter(granted_date__lt = lastdate)\ .exclude(survey_mail_send=True)\ .exclude(mail_state = 'END') - self.surveymails_to_object(supported, type=typefield[count]) - count += 1 + self.surveymails_to_object(supported, type=typ) def handle(self, *args, **options):