changed sending of last mails in sendmails.py and in views.py
This commit is contained in:
parent
21cfd50972
commit
7a99176b23
2 changed files with 97 additions and 43 deletions
|
@ -35,14 +35,22 @@ class Command(BaseCommand):
|
|||
'name': name,
|
||||
'pid': pid,
|
||||
'SURVEYPREFIX': SURVEYPREFIX, }
|
||||
mail_template = get_template('input/survey_mail.txt')
|
||||
txt_mail_template = get_template('input/survey_mail.txt')
|
||||
html_mail_template = get_template('input/survey_mail.html')
|
||||
try:
|
||||
survey_mail = EmailMessage('Dein Feedback zur Förderung durch Wikimedia Deutschland',
|
||||
mail_template.render(context),
|
||||
IF_EMAIL,
|
||||
[email],
|
||||
bcc=[SURVEY_EMAIL])
|
||||
survey_mail.send(fail_silently=False)
|
||||
subject, from_email, to = 'Dein Feedback zur Förderung durch Wikimedia Deutschland', IF_EMAIL, email
|
||||
text_content = txt_mail_template.render(context)
|
||||
html_content = html_mail_template.render(context)
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, [to], bcc=[SURVEY_EMAIL])
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
msg.send()
|
||||
|
||||
#survey_mail = EmailMessage('Dein Feedback zur Förderung durch Wikimedia Deutschland',
|
||||
# mail_template.render(context),
|
||||
# IF_EMAIL,
|
||||
# [email],
|
||||
# bcc=[SURVEY_EMAIL])
|
||||
#survey_mail.send(fail_silently=False)
|
||||
except BadHeaderError:
|
||||
return HttpResponse('Invalid header found.')
|
||||
|
||||
|
@ -52,20 +60,28 @@ class Command(BaseCommand):
|
|||
''' end of project reached '''
|
||||
# get all projects which ended
|
||||
|
||||
print(Project.objects.filter(end__lt = date.today()))
|
||||
old = Project.objects.filter(end__lt = date.today())\
|
||||
.exclude(end_mail_send = True)
|
||||
|
||||
mail_template = get_template('input/if_end_of_project.txt')
|
||||
txt_mail_template = get_template('input/if_end_of_project.txt')
|
||||
html_mail_template = get_template('input/if_end_of_project.html')
|
||||
|
||||
for project in old:
|
||||
context = {'project': project}
|
||||
context['URLPREFIX'] = settings.URLPREFIX
|
||||
try:
|
||||
send_mail('Projektende erreicht',
|
||||
mail_template.render(context),
|
||||
IF_EMAIL,
|
||||
['luca@cannabinieri.de'],
|
||||
fail_silently=False)
|
||||
subject, from_email, to = 'Projektende erreicht', IF_EMAIL, IF_EMAIL
|
||||
text_content = txt_mail_template.render(context)
|
||||
html_content = html_mail_template.render(context)
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
msg.send()
|
||||
|
||||
#send_mail('Projektende erreicht',
|
||||
# mail_template.render(context),
|
||||
# IF_EMAIL,
|
||||
# [IF_EMAIL],
|
||||
# fail_silently=False)
|
||||
project.end_mail_send = True
|
||||
project.save()
|
||||
except BadHeaderError:
|
||||
|
@ -80,24 +96,42 @@ class Command(BaseCommand):
|
|||
approved_end = Project.objects.filter(status = 'END')\
|
||||
.exclude(end_mail_send = False)
|
||||
print(approved_end)
|
||||
mail_template = get_template('input/if_end_of_project_approved.txt')
|
||||
informMail_template = get_template('input/if_end_of_project_orginformed.txt')
|
||||
txt_mail_template = get_template('input/if_end_of_project_approved.txt')
|
||||
html_mail_template = get_template('input/if_end_of_project_approved.html')
|
||||
|
||||
txt_informMail_template = get_template('input/if_end_of_project_orginformed.txt')
|
||||
html_informMail_template = get_template('input/if_end_of_project_orginformed.html')
|
||||
# send the mail to project.email, which would be the mail of the volunteer filling out the form
|
||||
|
||||
for project in approved_end:
|
||||
context = {'project': project}
|
||||
context['URLPREFIX'] = settings.URLPREFIX
|
||||
try:
|
||||
send_mail('Projektende erreicht',
|
||||
mail_template.render(context),
|
||||
IF_EMAIL,
|
||||
[project.email],
|
||||
fail_silently=False)
|
||||
send_mail('Projektorganisator*in wurde informiert',
|
||||
informMail_template.render(context),
|
||||
IF_EMAIL,
|
||||
[IF_EMAIL],
|
||||
fail_silently=False)
|
||||
subject, from_email, to = 'Projektende erreicht', IF_EMAIL, project.email
|
||||
text_content = txt_mail_template.render(context)
|
||||
html_content = html_mail_template.render(context)
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
msg.send()
|
||||
|
||||
inform_subject, inform_from_email, inform_to = Projektorganisator*in wurde informiert', IF_EMAIL, IF_EMAIL
|
||||
inform_text_content = txt_informMail_template.render(context)
|
||||
inform_html_content = html_informMail_template.render(context)
|
||||
inform_msg = EmailMultiAlternatives(inform_subject, inform_text_content, inform_from_email, [inform_to])
|
||||
inform_msg.attach_alternative(html_content, "text/html")
|
||||
inform_msg.send()
|
||||
|
||||
|
||||
#send_mail('Projektende erreicht',
|
||||
# mail_template.render(context),
|
||||
# IF_EMAIL,
|
||||
# [project.email],
|
||||
# fail_silently=False)
|
||||
#send_mail('Projektorganisator*in wurde informiert',
|
||||
# informMail_template.render(context),
|
||||
# IF_EMAIL,
|
||||
# [IF_EMAIL],
|
||||
# fail_silently=False)
|
||||
|
||||
project.end_mail_send = True
|
||||
project.save()
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.shortcuts import render
|
|||
from django.forms import modelformset_factory
|
||||
from django.http import HttpResponse
|
||||
from formtools.wizard.views import CookieWizardView
|
||||
from django.core.mail import send_mail, BadHeaderError
|
||||
from django.core.mail import send_mail, BadHeaderError, EmailMultiAlternatives
|
||||
from django.conf import settings
|
||||
from django.template.loader import get_template
|
||||
from django.template import Context
|
||||
|
@ -227,22 +227,42 @@ class ExternView(CookieWizardView):
|
|||
context = { 'data': data }
|
||||
try:
|
||||
# - mail with entered data to the Volunteer
|
||||
mail_template = get_template('input/ifg_volunteer_mail.txt')
|
||||
send_mail(
|
||||
'Formular ausgefüllt',
|
||||
mail_template.render(context),
|
||||
IF_EMAIL,
|
||||
[data['email']],
|
||||
fail_silently=False)
|
||||
# - mail to IF with link to accept/decline
|
||||
mail_template = get_template('input/if_mail.txt')
|
||||
send_mail(
|
||||
'Formular ausgefüllt',
|
||||
mail_template.render(context),
|
||||
IF_EMAIL,
|
||||
[IF_EMAIL],
|
||||
fail_silently=False)
|
||||
# raise SMTPException("testing pupose only")
|
||||
|
||||
txt_mail_template = get_template('input/ifg_volunteer_mail.txt')
|
||||
html_mail_template = get_template('input/ifg_volunteer_mail.html')
|
||||
|
||||
subject, from_email, to = 'Formular ausgefüllt', IF_EMAIL, data['email']
|
||||
text_content = txt_mail_template.render(context)
|
||||
html_content = html_mail_template.render(context)
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
msg.send()
|
||||
|
||||
#send_mail(
|
||||
# 'Formular ausgefüllt',
|
||||
# mail_template.render(context),
|
||||
# IF_EMAIL,
|
||||
# [data['email']],
|
||||
# fail_silently=False)
|
||||
## - mail to IF with link to accept/decline
|
||||
|
||||
txt_mail_template = get_template('input/if_mail.txt')
|
||||
html_mail_template = get_template('input/if_mail.html')
|
||||
|
||||
subject, from_email, to = 'Formular ausgefüllt', IF_EMAIL, IF_EMAIL
|
||||
text_content = txt_mail_template.render(context)
|
||||
html_content = html_mail_template.render(context)
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
msg.send()
|
||||
|
||||
#send_mail(
|
||||
# 'Formular ausgefüllt',
|
||||
# mail_template.render(context),
|
||||
# IF_EMAIL,
|
||||
# [IF_EMAIL],
|
||||
# fail_silently=False)
|
||||
## raise SMTPException("testing pupose only")
|
||||
|
||||
except BadHeaderError:
|
||||
modell.delete()
|
||||
|
|
Loading…
Reference in a new issue