|
|
@ -4,7 +4,7 @@ from django.core.management.base import BaseCommand, CommandError |
|
|
|
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, Library |
|
|
|
from input.settings import URLPREFIX, IF_EMAIL |
|
|
|
|
|
|
|
class Command(BaseCommand): |
|
|
@ -18,19 +18,23 @@ class Command(BaseCommand): |
|
|
|
- travel: mail 3 weeks after end of project. |
|
|
|
|
|
|
|
- assumed end of project (/project) reached: mail to IF, link to project-editpage |
|
|
|
|
|
|
|
- 4 weeks after end of project reached: mail with surveylink |
|
|
|
''' |
|
|
|
|
|
|
|
help = '''This command sends mail with some links to the database or to the survey |
|
|
|
after some amount of time.''' |
|
|
|
|
|
|
|
def handle(self, *args, **options): |
|
|
|
def survey_link(self, email, type, pid, name, realname): |
|
|
|
print(f'send surveylinkemail to {email}...') |
|
|
|
|
|
|
|
# get all projects which ended 3 weeks ago |
|
|
|
old = Project.objects.filter(end__lt = date.today() - timedelta(days=21))\ |
|
|
|
def end_of_projects_reached(self): |
|
|
|
''' end of project reached ''' |
|
|
|
# get all projects which ended |
|
|
|
# - timedelta(days=21)) |
|
|
|
old = Project.objects.filter(end__lt = date.today())\ |
|
|
|
.exclude(end_mail_send = True) |
|
|
|
|
|
|
|
|
|
|
|
print(old) |
|
|
|
mail_template = get_template('input/if_end_of_project.txt') |
|
|
|
for project in old: |
|
|
|
context = {'project': project} |
|
|
@ -47,4 +51,20 @@ class Command(BaseCommand): |
|
|
|
except BadHeaderError: |
|
|
|
return HttpResponse('Invalid header found.') |
|
|
|
|
|
|
|
self.stdout.write(self.style.SUCCESS('end_of_projects_reached() executed.')) |
|
|
|
|
|
|
|
|
|
|
|
def handle(self, *args, **options): |
|
|
|
|
|
|
|
self.end_of_projects_reached() |
|
|
|
|
|
|
|
supported = Library.objects.filter(granted=True) |
|
|
|
print(supported) |
|
|
|
for item in supported: |
|
|
|
self.survey_link(email=item.email, |
|
|
|
type=item.type, |
|
|
|
pid=9999, ## TODO |
|
|
|
name=item.library, |
|
|
|
realname=item.realname) |
|
|
|
|
|
|
|
self.stdout.write(self.style.SUCCESS('sendmails custom command executed')) |