forked from beba/foerderbarometer
simplified code
This commit is contained in:
parent
d3f18b0b93
commit
1495621ef0
|
|
@ -1,9 +1,8 @@
|
||||||
from datetime import date, timedelta
|
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.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.core.mail import EmailMultiAlternatives
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
@ -52,7 +51,7 @@ class Command(BaseCommand):
|
||||||
# bcc=[SURVEY_EMAIL])
|
# bcc=[SURVEY_EMAIL])
|
||||||
#survey_mail.send(fail_silently=False)
|
#survey_mail.send(fail_silently=False)
|
||||||
except BadHeaderError:
|
except BadHeaderError:
|
||||||
return HttpResponse('Invalid header found.')
|
return HttpResponse('Invalid header found.') # FIXME HttpResponse???
|
||||||
|
|
||||||
print(f'send surveylinkemail to {email}...')
|
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'''
|
'''send survey link 2 weeks after mailadresss, mailinglist or businesscards are granted'''
|
||||||
lastdate = date.today() - timedelta(days=14)
|
lastdate = date.today() - timedelta(days=14)
|
||||||
|
|
||||||
typefield = ('MAIL','VIS','LIST')
|
models = Email, BusinessCard, List
|
||||||
count = 0
|
types = 'MAIL', 'VIS', 'LIST'
|
||||||
for c in ('Email', 'BusinessCard', 'List'):
|
|
||||||
# get class via string
|
for model, typ in zip(models, types):
|
||||||
supported = getattr(sys.modules[__name__], c).objects.filter(granted=True)\
|
supported = model.objects.filter(granted=True)\
|
||||||
.filter(granted_date__lt = lastdate)\
|
.filter(granted_date__lt = lastdate)\
|
||||||
.exclude(survey_mail_send=True)\
|
.exclude(survey_mail_send=True)\
|
||||||
.exclude(mail_state = 'END')
|
.exclude(mail_state = 'END')
|
||||||
self.surveymails_to_object(supported, type=typefield[count])
|
self.surveymails_to_object(supported, type=typ)
|
||||||
count += 1
|
|
||||||
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue