Browse Source

changed sending of last mails in sendmails.py and in views.py

master
alpcentaur 1 year ago
parent
commit
34857ccf03
2 changed files with 97 additions and 43 deletions
  1. +60
    -26
      input/management/commands/sendmails.py
  2. +37
    -17
      input/views.py

+ 60
- 26
input/management/commands/sendmails.py View File

@ -35,14 +35,22 @@ class Command(BaseCommand):
'name': name, 'name': name,
'pid': pid, 'pid': pid,
'SURVEYPREFIX': SURVEYPREFIX, } '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: 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: except BadHeaderError:
return HttpResponse('Invalid header found.') return HttpResponse('Invalid header found.')
@ -52,20 +60,28 @@ class Command(BaseCommand):
''' end of project reached ''' ''' end of project reached '''
# get all projects which ended # get all projects which ended
print(Project.objects.filter(end__lt = date.today()))
old = Project.objects.filter(end__lt = date.today())\ old = Project.objects.filter(end__lt = date.today())\
.exclude(end_mail_send = True) .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: for project in old:
context = {'project': project} context = {'project': project}
context['URLPREFIX'] = settings.URLPREFIX context['URLPREFIX'] = settings.URLPREFIX
try: 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.end_mail_send = True
project.save() project.save()
except BadHeaderError: except BadHeaderError:
@ -80,24 +96,42 @@ class Command(BaseCommand):
approved_end = Project.objects.filter(status = 'END')\ approved_end = Project.objects.filter(status = 'END')\
.exclude(end_mail_send = False) .exclude(end_mail_send = False)
print(approved_end) 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 # send the mail to project.email, which would be the mail of the volunteer filling out the form
for project in approved_end: for project in approved_end:
context = {'project': project} context = {'project': project}
context['URLPREFIX'] = settings.URLPREFIX context['URLPREFIX'] = settings.URLPREFIX
try: 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.end_mail_send = True
project.save() project.save()

+ 37
- 17
input/views.py View File

@ -5,7 +5,7 @@ from django.shortcuts import render
from django.forms import modelformset_factory from django.forms import modelformset_factory
from django.http import HttpResponse from django.http import HttpResponse
from formtools.wizard.views import CookieWizardView 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.conf import settings
from django.template.loader import get_template from django.template.loader import get_template
from django.template import Context from django.template import Context
@ -227,22 +227,42 @@ class ExternView(CookieWizardView):
context = { 'data': data } context = { 'data': data }
try: try:
# - mail with entered data to the Volunteer # - 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: except BadHeaderError:
modell.delete() modell.delete()

Loading…
Cancel
Save