1
0
Fork 0

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

This commit is contained in:
Benni Bärmann 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.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'))

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_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.')