Browse Source

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

master
Benni Baermann 4 years ago
parent
commit
f2d209688b
3 changed files with 30 additions and 10 deletions
  1. +17
    -4
      input/management/commands/sendmails.py
  2. +9
    -0
      input/templates/input/if_end_of_project.txt
  3. +4
    -6
      input/views.py

+ 17
- 4
input/management/commands/sendmails.py 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'))

+ 9
- 0
input/templates/input/if_end_of_project.txt 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

+ 4
- 6
input/views.py 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.')

Loading…
Cancel
Save