added MAIL, VIS and LIST to sendmails command
This commit is contained in:
parent
275741ab47
commit
02d5a542bc
1 changed files with 21 additions and 3 deletions
|
@ -1,10 +1,11 @@
|
|||
from datetime import date, timedelta
|
||||
import sys
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.template.loader import get_template
|
||||
from django.core.mail import send_mail, BadHeaderError
|
||||
|
||||
from input.models import Project, Library, HonoraryCertificate, Travel
|
||||
from input.models import Project, Library, HonoraryCertificate, Travel, Email, BusinessCard, List
|
||||
from input.settings import URLPREFIX, IF_EMAIL, SURVEYPREFIX
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -66,15 +67,18 @@ class Command(BaseCommand):
|
|||
|
||||
self.stdout.write(self.style.SUCCESS('end_of_projects_reached() executed.'))
|
||||
|
||||
def surveymails_to_object(self, supported, name, type='LIB'):
|
||||
def surveymails_to_object(self, supported, name='', type='LIB'):
|
||||
mytype=type
|
||||
myname = name
|
||||
for item in supported:
|
||||
if type == 'LIB':
|
||||
mytype = item.type
|
||||
elif type not in ('MAIL','VIS','LIST'):
|
||||
myname = getattr(item,name)
|
||||
self.survey_link(email=item.email,
|
||||
type=mytype,
|
||||
pid=f'{mytype}{item.pk}',
|
||||
name=getattr(item,name),
|
||||
name=myname,
|
||||
realname=item.realname)
|
||||
item.survey_mail_send = True
|
||||
item.save()
|
||||
|
@ -112,6 +116,19 @@ class Command(BaseCommand):
|
|||
.exclude(survey_mail_send=True)
|
||||
self.surveymails_to_object(supported, type='TRAV', name='request_url')
|
||||
|
||||
def surveymails_to_mail_vis_lis(self):
|
||||
'''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'):
|
||||
supported = getattr(sys.modules[__name__], c).objects.filter(granted=True)\
|
||||
.filter(granted_date__lt = lastdate)\
|
||||
.exclude(survey_mail_send=True)
|
||||
self.surveymails_to_object(supported, type=typefield[count])
|
||||
count += 1
|
||||
|
||||
|
||||
def handle(self, *args, **options):
|
||||
'''the main function which is called by the custom command'''
|
||||
|
@ -121,5 +138,6 @@ class Command(BaseCommand):
|
|||
self.surveymails_to_hon()
|
||||
self.surveymails_to_project()
|
||||
self.surveymails_to_travel()
|
||||
self.surveymails_to_mail_vis_lis()
|
||||
|
||||
self.stdout.write(self.style.SUCCESS('sendmails custom command executed'))
|
||||
|
|
Loading…
Reference in a new issue