WMDE
/
eva
forked from tohe/eva
7
1
Fork 0

mails will be send to departments now

This commit is contained in:
Benni Bärmann 2021-01-06 10:59:47 +01:00
parent d971798018
commit f08ed17bb2
4 changed files with 30 additions and 15 deletions

View File

@ -1,8 +1,10 @@
MAILS = {'IT': {'TEMPLATE': 'it_template.txt',
EVA_MAIL = 'benni.baermann@wikimedia.de'
MAILS = {'IT': {
'MAIL': 'it@wikimedia.de',
'DATA': ['laptop', 'os',],
},
'OFFICE': {'TEMPLATE': 'office_template',
'OFFICE': {
'MAIL': 'office@wikimedia.de',
'DATA': ['transponder',],
},

View File

@ -0,0 +1 @@
blurb

View File

@ -0,0 +1 @@
blarb

View File

@ -1,28 +1,39 @@
from smtplib import SMTPException
from django.views.generic.edit import CreateView
from django.urls import reverse
from django.http import HttpResponse
from django.core.mail import send_mail, BadHeaderError
from django.template.loader import get_template
from .models import Employee
from .forms import EmployeeForm
from .settings import MAILS
from .settings import MAILS, EVA_MAIL
def success(request):
return HttpResponse("gut gemacht!")
def send_mail(department):
def send_mail_to_department(department):
'send a mail to the given department with the nececcary notifications'
print(f'send mail to department {department}')
print(f'send mail to department {department}...')
context = {}
try:
mail_template = get_template(f'evapp/{department}_mail.txt')
send_mail(
'EVA: Neuzugang',
mail_template.render(context),
EVA_MAIL,
[MAILS[department]['MAIL']],
fail_silently=False)
except BadHeaderError:
# modell.delete()
return HttpResponse('Invalid header found. Data not saved!')
except SMTPException:
# modell.delete()
return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!')
# context = { 'data': data }
# try:
# mail_template = get_template('input/it_mail.txt')
# send_mail(
# 'EVA: Neuzugang',
# mail_template.render(context),
# IF_EMAIL,
# [data['email']],
# fail_silently=False)
class EvaFormView(CreateView):
model = Employee
@ -33,6 +44,6 @@ class EvaFormView(CreateView):
def form_valid(self, form):
for dep in MAILS:
send_mail(dep)
send_mail_to_department(dep)
return super().form_valid(form)