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

more steps toward a formtools wizard. stil not really working

This commit is contained in:
Benni Bärmann 2021-01-12 10:57:21 +01:00
parent 74cc2898cb
commit 659c7f3d34
2 changed files with 42 additions and 14 deletions

View File

@ -30,13 +30,31 @@
<h1> <h1>
E V A - Eintritt, Veränderung, Austritt E V A - Eintritt, Veränderung, Austritt
</h1> </h1>
<p>Schritt {{ wizard.steps.step1 }} von {{ wizard.steps.count }}</p>
<form action="" method="post"> <form action="" method="post">
{% csrf_token %} {% csrf_token %}
<table> <table>
{% if choice %}
Du hast {{choice}} ausgewählt.
{% endif %}
{{ wizard.management_form }}
{% if wizard.form.forms %}
{{ wizard.form.management_form }}
{% for form in wizard.form.forms %}
{{ form }} {{ form }}
{% endfor %}
{% else %}
{{ wizard.form }}
{% endif %}
</table> </table>
<button type="submit" value="submit">Abschicken</button> <p>
<span style="color: red">*</span> Pflichtfeld
<p>
{% if wizard.steps.prev %}
<button formnovalidate="formnovalidate" name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">Zurück</button>
{% endif %}
<button type="submit" value="{% trans "Weiter" %}">Weiter</button>
</form> </form>
<p>
</center> </center>
{% endblock %} {% endblock %}

View File

@ -5,26 +5,28 @@ 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.core.mail import send_mail, BadHeaderError
from django.template.loader import get_template from django.template.loader import get_template
from formtools.wizard.views import CookieWizardView
from django.shortcuts import render
from .models import Employee from .models import Employee
from .forms import EmployeeForm from .forms import EmployeeForm, PersonalForm, WorkingForm
from .settings import MAILS, EVA_MAIL from .settings import MAILS, EVA_MAIL
def success(request): def success(request):
return HttpResponse("gut gemacht!") return HttpResponse("gut gemacht!")
def send_mail_to_department(department, form): def send_mail_to_department(department, data):
'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}...')
model = form.save() # model = form.save() # maybe we dont need to save here and get the model instance in another way?
context = {'data': {}} context = {'data': data}
# add all relevant fields of the form to the template context # add all relevant fields of the form to the template context
data = MAILS[department]['DATA'] # data = MAILS[department]['DATA']
for key in data: # for key in data:
context['data'][key] = form.cleaned_data[key] # context['data'][key] = form.cleaned_data[key]
try: try:
mail_template = get_template(f'evapp/{department}_mail.txt') mail_template = get_template(f'evapp/{department}_mail.txt')
@ -42,15 +44,23 @@ def send_mail_to_department(department, form):
return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!') return HttpResponse('Error in sending mails (propably wrong adress?). Data not saved!')
class EvaFormView(CreateView): class EvaFormView(CookieWizardView):
model = Employee model = Employee
form_class = EmployeeForm template_name = 'evapp/employee_form.html'
form_list = [PersonalForm, WorkingForm]
# form_class = EmployeeForm
def get_success_url(self): def get_success_url(self):
return reverse('success') return reverse('success')
def form_valid(self, form): def done(self, form_list, **kwargs):
# self.model.save()
form_data = [form.cleaned_data for form in form_list]
for dep in MAILS: for dep in MAILS:
send_mail_to_department(dep, form) send_mail_to_department(dep, form_data)
return render(self.request, 'evapp/dataloop.txt', {
'data': form_data,
})
return super().form_valid(form) return super().form_valid(form)