more steps toward a formtools wizard. stil not really working
This commit is contained in:
parent
74cc2898cb
commit
659c7f3d34
|
@ -30,13 +30,31 @@
|
|||
<h1>
|
||||
E V A - Eintritt, Veränderung, Austritt
|
||||
</h1>
|
||||
|
||||
<p>Schritt {{ wizard.steps.step1 }} von {{ wizard.steps.count }}</p>
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{form}}
|
||||
{% 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 }}
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{{ wizard.form }}
|
||||
{% endif %}
|
||||
</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>
|
||||
<p>
|
||||
</center>
|
||||
{% endblock %}
|
||||
|
|
|
@ -5,26 +5,28 @@ 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 formtools.wizard.views import CookieWizardView
|
||||
from django.shortcuts import render
|
||||
|
||||
from .models import Employee
|
||||
from .forms import EmployeeForm
|
||||
from .forms import EmployeeForm, PersonalForm, WorkingForm
|
||||
from .settings import MAILS, EVA_MAIL
|
||||
|
||||
def success(request):
|
||||
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'
|
||||
|
||||
print(f'send mail to department {department}...')
|
||||
|
||||
model = form.save()
|
||||
context = {'data': {}}
|
||||
# model = form.save() # maybe we dont need to save here and get the model instance in another way?
|
||||
context = {'data': data}
|
||||
|
||||
# add all relevant fields of the form to the template context
|
||||
data = MAILS[department]['DATA']
|
||||
for key in data:
|
||||
context['data'][key] = form.cleaned_data[key]
|
||||
# data = MAILS[department]['DATA']
|
||||
# for key in data:
|
||||
# context['data'][key] = form.cleaned_data[key]
|
||||
|
||||
try:
|
||||
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!')
|
||||
|
||||
|
||||
class EvaFormView(CreateView):
|
||||
class EvaFormView(CookieWizardView):
|
||||
model = Employee
|
||||
form_class = EmployeeForm
|
||||
template_name = 'evapp/employee_form.html'
|
||||
form_list = [PersonalForm, WorkingForm]
|
||||
|
||||
# form_class = EmployeeForm
|
||||
|
||||
def get_success_url(self):
|
||||
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:
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue