You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.6 KiB

  1. from datetime import date, timedelta
  2. from django.core.management.base import BaseCommand, CommandError
  3. from django.template.loader import get_template
  4. from django.core.mail import send_mail, BadHeaderError
  5. from input.models import Project
  6. from input.settings import URLPREFIX, IF_EMAIL
  7. class Command(BaseCommand):
  8. ''' mails will be send here:
  9. - two weeks after confirmation of support for volunteer (/extern) send link
  10. with surveylink
  11. - same for HonoraryCertificate and accreditation (/intern)
  12. - travel: mail 3 weeks after end of project.
  13. - assumed end of project (/project) reached: mail to IF, link to project-editpage
  14. '''
  15. help = '''This command sends mail with some links to the database or to the survey
  16. after some amount of time.'''
  17. def handle(self, *args, **options):
  18. # get all projects which ended 3 weeks ago
  19. old = Project.objects.filter(end__lt = date.today() - timedelta(days=30))
  20. print(old)
  21. mail_template = get_template('input/if_end_of_project.txt')
  22. for project in old:
  23. context = {'project': project}
  24. context['URLPREFIX'] = URLPREFIX
  25. print(context)
  26. try:
  27. send_mail('Projektende erreicht',
  28. mail_template.render(context),
  29. IF_EMAIL,
  30. [IF_EMAIL],
  31. fail_silently=False)
  32. except BadHeaderError:
  33. return HttpResponse('Invalid header found.')
  34. self.stdout.write(self.style.SUCCESS('sendmails custom command executed'))