Modal and other tweaks
* removes WIKI_URL, replaces with HELP_LINK since it was the same before as well * refactors modal form processing (process_request()) * modal form can now display errors directly inside the modal (as intended by the devs) * modals now properly support the GET-POST workflow that is intended by the devs. More information here: https://github.com/trco/django-bootstrap-modal-forms/issues/183 * Improves label-field linking in generic_table_form_body.html * removes isDeleteForm attribute from modal_form_script.html
This commit is contained in:
+15
-19
@@ -9,14 +9,15 @@ Created on: 16.11.20
|
||||
from abc import abstractmethod
|
||||
|
||||
from bootstrap_modal_forms.forms import BSModalForm
|
||||
from bootstrap_modal_forms.utils import is_ajax
|
||||
from django import forms
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.gis.forms import GeometryField, OSMWidget
|
||||
from django.contrib.gis.geos import Polygon
|
||||
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 import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@@ -44,6 +45,7 @@ class BaseForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.instance = kwargs.pop("instance", None)
|
||||
self.user = kwargs.pop("user", None)
|
||||
self.request = kwargs.pop("request", None)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# Check for required fields
|
||||
@@ -170,25 +172,19 @@ class BaseModalForm(BaseForm, BSModalForm):
|
||||
template = self.template
|
||||
if request.method == "POST":
|
||||
if self.is_valid():
|
||||
self.save()
|
||||
messages.success(
|
||||
request,
|
||||
msg_success
|
||||
)
|
||||
return redirect(redirect_url)
|
||||
else:
|
||||
messages.error(
|
||||
request,
|
||||
msg_error,
|
||||
extra_tags="danger"
|
||||
)
|
||||
for field, error in self.errors.items():
|
||||
messages.error(
|
||||
if not is_ajax(request.META):
|
||||
self.save()
|
||||
messages.success(
|
||||
request,
|
||||
"{}: {}".format(self.fields[field].label, _(error[0])),
|
||||
extra_tags="danger"
|
||||
msg_success
|
||||
)
|
||||
return redirect(redirect_url)
|
||||
return HttpResponseRedirect(redirect_url)
|
||||
else:
|
||||
context = {
|
||||
"form": self,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
elif request.method == "GET":
|
||||
context = {
|
||||
"form": self,
|
||||
|
||||
Reference in New Issue
Block a user