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