From 1458a1cb6b15163b3fdc511fa7cee40027438bb9 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Mon, 26 Oct 2020 13:23:05 +0100 Subject: [PATCH] sned mails for Travel objects 3 weeks after the related project has ended --- input/management/commands/sendmails.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/input/management/commands/sendmails.py b/input/management/commands/sendmails.py index 8fa133f..9f23e11 100644 --- a/input/management/commands/sendmails.py +++ b/input/management/commands/sendmails.py @@ -4,7 +4,7 @@ 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 +from input.models import Project, Library, HonoraryCertificate, Travel from input.settings import URLPREFIX, IF_EMAIL, SURVEYPREFIX class Command(BaseCommand): @@ -15,11 +15,11 @@ class Command(BaseCommand): - same for HonoraryCertificate (/intern) - - TODO: travel: mail 3 weeks after end of project. + - travel: mail 3 weeks after end of project. - assumed end of project (/project) reached: mail to IF, link to project-editpage - - TODO: 4 weeks after end of project reached: mail with surveylink + - 4 weeks after end of project reached: mail with surveylink ''' help = '''This command sends mail with some links to the database or to the survey @@ -116,6 +116,20 @@ class Command(BaseCommand): def surveymails_to_travel(self): '''send survey link 3 weeks after end of project reached''' + + supported = Travel.objects.filter(project__granted=True)\ + .filter(project__granted_date__lt = date.today() - timedelta(days=21))\ + .exclude(survey_mail_send=True) + print(supported) + for item in supported: + self.survey_link(email=item.email, + type='TRAV', + pid=9999, ## TODO + name=item.request_url, + realname=item.realname) + item.survey_mail_send = True + item.save() + pass