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 42f068a2..5de77a79 100644 Binary files a/locale/de/LC_MESSAGES/django.mo and b/locale/de/LC_MESSAGES/django.mo differ 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"