Modal forms
* adds new POST functionality in NewStateModalForm, which does not use the super classes process_request() method * adds explaining comments on the is_ajax() call * updates translations
This commit is contained in:
parent
7dbf4d5b91
commit
198462b051
@ -5,11 +5,12 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
|||||||
Created on: 04.12.20
|
Created on: 04.12.20
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from bootstrap_modal_forms.utils import is_ajax
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest, HttpResponseRedirect
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import render
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices
|
from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices
|
||||||
@ -153,19 +154,24 @@ class NewStateModalForm(BaseModalForm):
|
|||||||
template = self.template
|
template = self.template
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if self.is_valid():
|
if self.is_valid():
|
||||||
is_before_state = bool(request.GET.get("before", False))
|
# Modal forms send one POST for checking on data validity. This can be used to return possible errors
|
||||||
self.save(is_before_state=is_before_state)
|
# on the form. A second POST (if no errors occured) is sent afterwards and needs to process the
|
||||||
messages.success(
|
# saving/commiting of the data to the database. is_ajax() performs this check. The first request is
|
||||||
request,
|
# an ajax call, the second is a regular form POST.
|
||||||
msg_success
|
if not is_ajax(request.META):
|
||||||
)
|
is_before_state = bool(request.GET.get("before", False))
|
||||||
return redirect(redirect_url)
|
self.save(is_before_state=is_before_state)
|
||||||
|
messages.success(
|
||||||
|
request,
|
||||||
|
msg_success
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect(redirect_url)
|
||||||
else:
|
else:
|
||||||
messages.info(
|
context = {
|
||||||
request,
|
"form": self,
|
||||||
msg_error
|
}
|
||||||
)
|
context = BaseContext(request, context).context
|
||||||
return redirect(redirect_url)
|
return render(request, template, context)
|
||||||
elif request.method == "GET":
|
elif request.method == "GET":
|
||||||
context = {
|
context = {
|
||||||
"form": self,
|
"form": self,
|
||||||
|
@ -173,6 +173,10 @@ class BaseModalForm(BaseForm, BSModalForm):
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if self.is_valid():
|
if self.is_valid():
|
||||||
if not is_ajax(request.META):
|
if not is_ajax(request.META):
|
||||||
|
# Modal forms send one POST for checking on data validity. This can be used to return possible errors
|
||||||
|
# on the form. A second POST (if no errors occured) is sent afterwards and needs to process the
|
||||||
|
# saving/commiting of the data to the database. is_ajax() performs this check. The first request is
|
||||||
|
# an ajax call, the second is a regular form POST.
|
||||||
self.save()
|
self.save()
|
||||||
messages.success(
|
messages.success(
|
||||||
request,
|
request,
|
||||||
|
Binary file not shown.
@ -410,7 +410,7 @@ msgstr "Termine und Fristen"
|
|||||||
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:14
|
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:14
|
||||||
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:14
|
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:14
|
||||||
msgid "Add new deadline"
|
msgid "Add new deadline"
|
||||||
msgstr "Neue Frist hinzufügen"
|
msgstr "Frist/Termin hinzufügen"
|
||||||
|
|
||||||
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:28
|
#: compensation/templates/compensation/detail/compensation/includes/deadlines.html:28
|
||||||
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:28
|
#: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:28
|
||||||
@ -594,7 +594,7 @@ msgstr "Maßnahme hinzugefügt"
|
|||||||
#: compensation/views/compensation_views.py:219
|
#: compensation/views/compensation_views.py:219
|
||||||
#: compensation/views/eco_account_views.py:265
|
#: compensation/views/eco_account_views.py:265
|
||||||
msgid "Deadline added"
|
msgid "Deadline added"
|
||||||
msgstr "Frist hinzugefügt"
|
msgstr "Frist/Termin hinzugefügt"
|
||||||
|
|
||||||
#: compensation/views/compensation_views.py:238
|
#: compensation/views/compensation_views.py:238
|
||||||
msgid "State removed"
|
msgid "State removed"
|
||||||
|
Loading…
Reference in New Issue
Block a user