From f2d209688bac36596c92f352c9b81347c8a2ae03 Mon Sep 17 00:00:00 2001 From: Benni Baermann Date: Thu, 22 Oct 2020 10:27:14 +0200 Subject: [PATCH] send mail 30 days after assumed end of project in sendmails command --- input/management/commands/sendmails.py | 21 +++++++++++++++++---- input/templates/input/if_end_of_project.txt | 9 +++++++++ input/views.py | 10 ++++------ 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 input/templates/input/if_end_of_project.txt diff --git a/input/management/commands/sendmails.py b/input/management/commands/sendmails.py index 3645b60..9366316 100644 --- a/input/management/commands/sendmails.py +++ b/input/management/commands/sendmails.py @@ -1,10 +1,11 @@ -from datetime import date +from datetime import date, timedelta from django.core.management.base import BaseCommand, CommandError -# from django.db.models.query import QuerySet +from django.template.loader import get_template +from django.core.mail import send_mail, BadHeaderError from input.models import Project - +from input.settings import URLPREFIX, IF_EMAIL class Command(BaseCommand): ''' mails will be send here: @@ -25,7 +26,19 @@ class Command(BaseCommand): def handle(self, *args, **options): # get all projects which ended 3 weeks ago - old = Project.objects.filter(end__lt = date.today()) + old = Project.objects.filter(end__lt = date.today() - timedelta(days=30)) print(old) + mail_template = get_template('input/if_end_of_project.txt') + for project in old: + context = {'project': project} + try: + send_mail('Projektende erreicht', + mail_template.render(context), + IF_EMAIL, + [IF_EMAIL], + fail_silently=False) + except BadHeaderError: + return HttpResponse('Invalid header found.') + self.stdout.write(self.style.SUCCESS('sendmails custom command executed')) diff --git a/input/templates/input/if_end_of_project.txt b/input/templates/input/if_end_of_project.txt new file mode 100644 index 0000000..3c3dd50 --- /dev/null +++ b/input/templates/input/if_end_of_project.txt @@ -0,0 +1,9 @@ +Hallo Team Ideenförderung! + +Das Project {{project.name}} hat am {{project.end}} sein vorraussichtliches Ende erreicht. + +Hier könnt ihr es in der Datenbank editieren: + +INSERT LINK here ID: {{project.pid}} + +mit freundlichen Grüßen, Eure Lieblingsdatenbank diff --git a/input/views.py b/input/views.py index 13094bb..c85e669 100644 --- a/input/views.py +++ b/input/views.py @@ -149,21 +149,19 @@ class ExternView(CookieWizardView): # - mail with entered data to the Volunteer mail_template = get_template('input/ifg_volunteer_mail.txt') send_mail( - 'form filled', + 'Formular ausgefüllt', mail_template.render(context), IF_EMAIL, [form.email], - fail_silently=False, - ) + fail_silently=False) # - mail to IF with link to accept/decline mail_template = get_template('input/if_mail.txt') send_mail( - 'form filled', + 'Formular ausgefüllt', mail_template.render(context), IF_EMAIL, [IF_EMAIL], - fail_silently=False, - ) + fail_silently=False) except BadHeaderError: return HttpResponse('Invalid header found.')