forked from beba/foerderbarometer
				
			changed sending of last mails in sendmails.py and in views.py
This commit is contained in:
		
							parent
							
								
									21cfd50972
								
							
						
					
					
						commit
						7a99176b23
					
				| 
						 | 
					@ -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',
 | 
					            subject, from_email, to = 'Dein Feedback zur Förderung durch Wikimedia Deutschland', IF_EMAIL, email
 | 
				
			||||||
                  mail_template.render(context),
 | 
					                text_content = txt_mail_template.render(context)
 | 
				
			||||||
                  IF_EMAIL,
 | 
					                html_content = html_mail_template.render(context)
 | 
				
			||||||
                  [email],
 | 
					                msg = EmailMultiAlternatives(subject, text_content, from_email, [to], bcc=[SURVEY_EMAIL])
 | 
				
			||||||
                  bcc=[SURVEY_EMAIL])
 | 
					                msg.attach_alternative(html_content, "text/html")
 | 
				
			||||||
            survey_mail.send(fail_silently=False)
 | 
					                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',
 | 
					                subject, from_email, to = 'Projektende erreicht', IF_EMAIL, IF_EMAIL
 | 
				
			||||||
                          mail_template.render(context),
 | 
					                text_content = txt_mail_template.render(context)
 | 
				
			||||||
                          IF_EMAIL,
 | 
					                html_content = html_mail_template.render(context)
 | 
				
			||||||
                          ['luca@cannabinieri.de'],
 | 
					                msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
 | 
				
			||||||
                          fail_silently=False)
 | 
					                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')
 | 
					        txt_mail_template = get_template('input/if_end_of_project_approved.txt')
 | 
				
			||||||
        informMail_template = get_template('input/if_end_of_project_orginformed.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',
 | 
					                subject, from_email, to = 'Projektende erreicht', IF_EMAIL, project.email
 | 
				
			||||||
                          mail_template.render(context),
 | 
					                text_content = txt_mail_template.render(context)
 | 
				
			||||||
                          IF_EMAIL,
 | 
					                html_content = html_mail_template.render(context)
 | 
				
			||||||
                          [project.email],
 | 
					                msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
 | 
				
			||||||
                          fail_silently=False)
 | 
					                msg.attach_alternative(html_content, "text/html")
 | 
				
			||||||
                send_mail('Projektorganisator*in wurde informiert',
 | 
					                msg.send()
 | 
				
			||||||
                          informMail_template.render(context),
 | 
					                
 | 
				
			||||||
                          IF_EMAIL,
 | 
					                inform_subject, inform_from_email, inform_to = Projektorganisator*in wurde informiert', IF_EMAIL, IF_EMAIL
 | 
				
			||||||
                          [IF_EMAIL],
 | 
					                inform_text_content = txt_informMail_template.render(context)
 | 
				
			||||||
                          fail_silently=False)
 | 
					                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()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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(
 | 
					            txt_mail_template = get_template('input/ifg_volunteer_mail.txt')
 | 
				
			||||||
                'Formular ausgefüllt',
 | 
					            html_mail_template = get_template('input/ifg_volunteer_mail.html')
 | 
				
			||||||
                mail_template.render(context),
 | 
					            
 | 
				
			||||||
                IF_EMAIL,
 | 
					            subject, from_email, to = 'Formular ausgefüllt', IF_EMAIL, data['email']
 | 
				
			||||||
                [data['email']],
 | 
					            text_content = txt_mail_template.render(context)
 | 
				
			||||||
                fail_silently=False)
 | 
					            html_content = html_mail_template.render(context)
 | 
				
			||||||
            #  - mail to IF with link to accept/decline
 | 
					            msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
 | 
				
			||||||
            mail_template = get_template('input/if_mail.txt')
 | 
					            msg.attach_alternative(html_content, "text/html")
 | 
				
			||||||
            send_mail(
 | 
					            msg.send()
 | 
				
			||||||
                'Formular ausgefüllt',
 | 
					            
 | 
				
			||||||
                mail_template.render(context),
 | 
					            #send_mail(
 | 
				
			||||||
                IF_EMAIL,
 | 
					            #    'Formular ausgefüllt',
 | 
				
			||||||
                [IF_EMAIL],
 | 
					            #    mail_template.render(context),
 | 
				
			||||||
                fail_silently=False)
 | 
					            #    IF_EMAIL,
 | 
				
			||||||
            # raise SMTPException("testing pupose only")
 | 
					            #    [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…
	
		Reference in New Issue