From 198462b05114861926de1a558d94438c624204e0 Mon Sep 17 00:00:00 2001 From: mipel Date: Thu, 19 Aug 2021 09:06:35 +0200 Subject: [PATCH] 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 --- compensation/forms.py | 34 +++++++++++++++++++------------- konova/forms.py | 4 ++++ locale/de/LC_MESSAGES/django.mo | Bin 18335 -> 18344 bytes locale/de/LC_MESSAGES/django.po | 4 ++-- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/compensation/forms.py b/compensation/forms.py index 33c9e946..7dfb8226 100644 --- a/compensation/forms.py +++ b/compensation/forms.py @@ -5,11 +5,12 @@ Contact: michel.peltriaux@sgdnord.rlp.de Created on: 04.12.20 """ +from bootstrap_modal_forms.utils import is_ajax from django import forms from django.contrib import messages from django.db import transaction -from django.http import HttpRequest -from django.shortcuts import redirect, render +from django.http import HttpRequest, HttpResponseRedirect +from django.shortcuts import render from django.utils.translation import gettext_lazy as _ from compensation.models import Payment, CompensationState, CompensationAction, UnitChoices @@ -153,19 +154,24 @@ class NewStateModalForm(BaseModalForm): template = self.template if request.method == "POST": if self.is_valid(): - is_before_state = bool(request.GET.get("before", False)) - self.save(is_before_state=is_before_state) - messages.success( - request, - msg_success - ) - return redirect(redirect_url) + # 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. + if not is_ajax(request.META): + is_before_state = bool(request.GET.get("before", False)) + self.save(is_before_state=is_before_state) + messages.success( + request, + msg_success + ) + return HttpResponseRedirect(redirect_url) else: - messages.info( - request, - msg_error - ) - return redirect(redirect_url) + context = { + "form": self, + } + context = BaseContext(request, context).context + return render(request, template, context) elif request.method == "GET": context = { "form": self, diff --git a/konova/forms.py b/konova/forms.py index d685292e..f07a08a5 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -173,6 +173,10 @@ class BaseModalForm(BaseForm, BSModalForm): if request.method == "POST": if self.is_valid(): 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() messages.success( request, diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 42f068a2804bf01fa927760167bc3d18ebe3d7b3..5de77a799fa32fbab1938e094a7144c950757abf 100644 GIT binary patch delta 2171 zcmXxk3ryBk7{~ELAcS%CigR{ZH&)({+Dx}=Q-#99_tS| z*&p)x>PT;?F{ZM>m{e>*#XXpghcFXI-Tf&{CZ5G4G=;{bKr$vOL?6~-0&c@q_&SE+ z5H7-DjKR+ejb~yRjB_ClzsAKlgPQmbYQhB<#}ye9NgQw%JIgVR>vgySUqL1K0X~XB z%*Ihv0oO4K=ZZXImN9t91x@UG(%wi%B@#eoT!N~w43+sNcYgfquM(O7xz`K$ZH6?H1%=C~+Ms^9{}ya0ziMYOD655<7^h^a$$t5!8HVP@Vk_ zefWdBf8Y5RszC3N5?gt+GZ{5eCaSUkCSnz;Lt9ZVwxL?O8x!%UyFP+??kwiw1hRW( z7F9s%Q}+ElBr(sFGSFe$fND_(K8A0i7V5*N@k30+Z%~#0h-&dK7>)OE4gQU)yoewl zt5DB%q27BNbr|2p&8%F78F`{V7z3zC<0`Nld_-xD@ZA zIuJ(IsyN1(=`2Q_iCRo%eY25)_WU)}#2u)KyHOeMcfOD6%wZP~VSqS@Pv8`)vIW%F z5b}(jHyxFDrn3Om*$VX3x_WnGD=OZJTIdZ-!CurM8bl>_8k6uM*5M33j{Y)R@p@-7 zYHQn3TXFz3@5iXq|7jWh*CDyeg#vtld6>P{?%ih8;pxK~JcoR#W&xE*{yN+0O4Qk@ zM|E%uYAbi3wq_T`<2$HC`ca)awvPU5FOG9Tm5-th*#*?zeUHlc4r+qmU2Mv2OQSG@ z>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-Do> z8&F&OENV-3qUPO;I{gQi(SIG1&$v*Gzv3g9S!wrfHR|y6U`PR}H&7G&?Bc&rXCboM zm~2c$RTRWU*n)b$*WC}JzLqn15yw%94tbB+)_&~#8u>G~_@@?UEw>Amp%SQbK7~s3 z1sCr`P1uhC45OYuiz;9Ybr!Cp4(UzQ``#S}YEf*B%{YKMy``wmRG}WM!*tw;>QtAz z{yJ)*FltLqU@+%)|UT>v{|j@4$I@ z2sOc{s7{Tc620o2#7N@1sCoZIJs(wX6G%YCb8!ain?eT4v<&rKu0XxmfP7h|2{W-D zRml*}!OyV_Cs3V94cSg+qdHWM0bGSDs1y0X%mK{BOW2@H|74(r@1Yime%$VTI%>~y vZ~+!!Ha4M7e;2BfH(cC5(&4+76|=6rt343f*73^rk+sDyMvZ*3cq;LK_8;n+ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index 77477acc..7c52cdef 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -410,7 +410,7 @@ msgstr "Termine und Fristen" #: compensation/templates/compensation/detail/compensation/includes/deadlines.html:14 #: compensation/templates/compensation/detail/eco_account/includes/deadlines.html:14 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/eco_account/includes/deadlines.html:28 @@ -594,7 +594,7 @@ msgstr "Maßnahme hinzugefügt" #: compensation/views/compensation_views.py:219 #: compensation/views/eco_account_views.py:265 msgid "Deadline added" -msgstr "Frist hinzugefügt" +msgstr "Frist/Termin hinzugefügt" #: compensation/views/compensation_views.py:238 msgid "State removed"