|
@ -1,10 +1,11 @@ |
|
|
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, CommandError |
|
|
from django.template.loader import get_template |
|
|
from django.template.loader import get_template |
|
|
from django.core.mail import send_mail, BadHeaderError |
|
|
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 |
|
|
from input.settings import URLPREFIX, IF_EMAIL, SURVEYPREFIX |
|
|
|
|
|
|
|
|
class Command(BaseCommand): |
|
|
class Command(BaseCommand): |
|
@ -66,15 +67,18 @@ class Command(BaseCommand): |
|
|
|
|
|
|
|
|
self.stdout.write(self.style.SUCCESS('end_of_projects_reached() executed.')) |
|
|
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 |
|
|
mytype=type |
|
|
|
|
|
myname = name |
|
|
for item in supported: |
|
|
for item in supported: |
|
|
if type == 'LIB': |
|
|
if type == 'LIB': |
|
|
mytype = item.type |
|
|
mytype = item.type |
|
|
|
|
|
elif type not in ('MAIL','VIS','LIST'): |
|
|
|
|
|
myname = getattr(item,name) |
|
|
self.survey_link(email=item.email, |
|
|
self.survey_link(email=item.email, |
|
|
type=mytype, |
|
|
type=mytype, |
|
|
pid=f'{mytype}{item.pk}', |
|
|
pid=f'{mytype}{item.pk}', |
|
|
name=getattr(item,name), |
|
|
|
|
|
|
|
|
name=myname, |
|
|
realname=item.realname) |
|
|
realname=item.realname) |
|
|
item.survey_mail_send = True |
|
|
item.survey_mail_send = True |
|
|
item.save() |
|
|
item.save() |
|
@ -112,6 +116,19 @@ class Command(BaseCommand): |
|
|
.exclude(survey_mail_send=True) |
|
|
.exclude(survey_mail_send=True) |
|
|
self.surveymails_to_object(supported, type='TRAV', name='request_url') |
|
|
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): |
|
|
def handle(self, *args, **options): |
|
|
'''the main function which is called by the custom command''' |
|
|
'''the main function which is called by the custom command''' |
|
@ -121,5 +138,6 @@ class Command(BaseCommand): |
|
|
self.surveymails_to_hon() |
|
|
self.surveymails_to_hon() |
|
|
self.surveymails_to_project() |
|
|
self.surveymails_to_project() |
|
|
self.surveymails_to_travel() |
|
|
self.surveymails_to_travel() |
|
|
|
|
|
self.surveymails_to_mail_vis_lis() |
|
|
|
|
|
|
|
|
self.stdout.write(self.style.SUCCESS('sendmails custom command executed')) |
|
|
self.stdout.write(self.style.SUCCESS('sendmails custom command executed')) |