send mail 30 days after assumed end of project in sendmails command

This commit is contained in:
Benni Baermann 2020-10-22 10:27:14 +02:00
parent 541b9d8f7e
commit f2d209688b
3 changed files with 30 additions and 10 deletions

View file

@ -1,10 +1,11 @@
from datetime import date from datetime import date, timedelta
from django.core.management.base import BaseCommand, CommandError 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.models import Project
from input.settings import URLPREFIX, IF_EMAIL
class Command(BaseCommand): class Command(BaseCommand):
''' mails will be send here: ''' mails will be send here:
@ -25,7 +26,19 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
# get all projects which ended 3 weeks ago # 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) 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')) self.stdout.write(self.style.SUCCESS('sendmails custom command executed'))

View file

@ -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

View file

@ -149,21 +149,19 @@ class ExternView(CookieWizardView):
# - mail with entered data to the Volunteer # - mail with entered data to the Volunteer
mail_template = get_template('input/ifg_volunteer_mail.txt') mail_template = get_template('input/ifg_volunteer_mail.txt')
send_mail( send_mail(
'form filled', 'Formular ausgefüllt',
mail_template.render(context), mail_template.render(context),
IF_EMAIL, IF_EMAIL,
[form.email], [form.email],
fail_silently=False, fail_silently=False)
)
# - mail to IF with link to accept/decline # - mail to IF with link to accept/decline
mail_template = get_template('input/if_mail.txt') mail_template = get_template('input/if_mail.txt')
send_mail( send_mail(
'form filled', 'Formular ausgefüllt',
mail_template.render(context), mail_template.render(context),
IF_EMAIL, IF_EMAIL,
[IF_EMAIL], [IF_EMAIL],
fail_silently=False, fail_silently=False)
)
except BadHeaderError: except BadHeaderError:
return HttpResponse('Invalid header found.') return HttpResponse('Invalid header found.')