mails will be send to departments now
This commit is contained in:
parent
d971798018
commit
f08ed17bb2
|
@ -1,8 +1,10 @@
|
||||||
MAILS = {'IT': {'TEMPLATE': 'it_template.txt',
|
EVA_MAIL = 'benni.baermann@wikimedia.de'
|
||||||
|
|
||||||
|
MAILS = {'IT': {
|
||||||
'MAIL': 'it@wikimedia.de',
|
'MAIL': 'it@wikimedia.de',
|
||||||
'DATA': ['laptop', 'os',],
|
'DATA': ['laptop', 'os',],
|
||||||
},
|
},
|
||||||
'OFFICE': {'TEMPLATE': 'office_template',
|
'OFFICE': {
|
||||||
'MAIL': 'office@wikimedia.de',
|
'MAIL': 'office@wikimedia.de',
|
||||||
'DATA': ['transponder',],
|
'DATA': ['transponder',],
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
blurb
|
|
@ -0,0 +1 @@
|
||||||
|
blarb
|
|
@ -1,28 +1,39 @@
|
||||||
|
from smtplib import SMTPException
|
||||||
|
|
||||||
from django.views.generic.edit import CreateView
|
from django.views.generic.edit import CreateView
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.http import HttpResponse
|
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 .models import Employee
|
||||||
from .forms import EmployeeForm
|
from .forms import EmployeeForm
|
||||||
from .settings import MAILS
|
from .settings import MAILS, EVA_MAIL
|
||||||
|
|
||||||
def success(request):
|
def success(request):
|
||||||
return HttpResponse("gut gemacht!")
|
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'
|
'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):
|
class EvaFormView(CreateView):
|
||||||
model = Employee
|
model = Employee
|
||||||
|
@ -33,6 +44,6 @@ class EvaFormView(CreateView):
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
for dep in MAILS:
|
for dep in MAILS:
|
||||||
send_mail(dep)
|
send_mail_to_department(dep)
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
Loading…
Reference in New Issue