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:
mipel 2021-08-17 15:27:49 +02:00
parent 833483b810
commit c82ee8afbc
8 changed files with 44 additions and 51 deletions

View File

@ -7,8 +7,7 @@ Created on: 16.11.20
"""
from django.http import HttpRequest
from konova.settings import HELP_LINK
from konova.sub_settings.context_settings import BASE_TITLE, WIKI_URL, BASE_FRONTEND_TITLE
from konova.sub_settings.context_settings import BASE_TITLE, HELP_LINK, BASE_FRONTEND_TITLE
class BaseContext:
@ -19,11 +18,9 @@ class BaseContext:
"base_title": BASE_TITLE,
"base_frontend_title": BASE_FRONTEND_TITLE,
"language": "en",
"wiki_url": WIKI_URL,
"user": None,
"current_role": None,
"help_link": HELP_LINK,
"modal_reload_page": "true", # must be string and lower case true, since it's used in JS code
}
def __init__(self, request: HttpRequest, additional_context: dict = {}):

View File

@ -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,

View File

@ -56,9 +56,6 @@ ZB_GROUP = "Registration office"
ETS_GROUP = "Conservation office"
# HELP PAGE LINK
HELP_LINK = "https://dienste.naturschutz.rlp.de/doku/doku.php?id=ksp:start"
# Needed to redirect to LANIS
## Values to be inserted are [zoom_level, x_coord, y_coord]
LANIS_LINK_TEMPLATE = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/index.php?lang=de&zl={}&x={}&y={}&bl=tk_rlp_tms_grau&bo=1&lo=0.8,0.8,0.8,0.6,0.8,0.8,0.8,0.8,0.8&layers=eiv_f,eiv_l,eiv_p,kom_f,kom_l,kom_p,oek_f,ema_f,mae&service=kartendienste_naturschutz"

View File

@ -9,4 +9,4 @@ Created on: 16.11.20
BASE_TITLE_SHORT = "KSP"
BASE_TITLE = "KSP - Kompensationsverzeichnis Service Portal"
BASE_FRONTEND_TITLE = "Kompensationsverzeichnis Service Portal"
WIKI_URL = "https://dienste.naturschutz.rlp.de/doku/doku.php?id=ksp:start"
HELP_LINK = "https://dienste.naturschutz.rlp.de/doku/doku.php?id=ksp:start"

View File

@ -32,7 +32,10 @@ SECRET_KEY = '5=9-)2)h$u9=!zrhia9=lj-2#cpcb8=#$7y+)l$5tto$3q(n_+'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",
]
# Authentication settings
LOGIN_URL = "/login/"

View File

@ -1,22 +1,23 @@
{% load i18n %}
<table class="table">
<tbody>
{% for field in form %}
<tr title="{{ field.help_text }}" class="{% if field.errors %}error{% endif %}">
<th scope="row" class="col-sm-3">
<label for="id_{{ field.name }}">{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></label>
<small>{{ field.help_text }}</small>
</th>
<td class="col-sm-9">
{{ field }}
{% for error in field.errors %}
<strong>{{ error }}</strong>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if form.has_required_fields %}
<small>{% trans 'Fields with * are required.' %}</small>
{% endif %}
<table class="table">
<tbody>
{% for field in form %}
<tr title="{{ field.help_text }}" class="{% if field.errors %}alert-danger{% endif %}">
<th scope="row" class="col-sm-3">
<label for="id_{{ field.name }}">{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></label>
<small>{{ field.help_text }}</small>
</th>
<td class="col-sm-9">
{{ field }}
{% for error in field.errors %}
<br>
<strong class="invalid">{{ error }}</strong>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if form.has_required_fields %}
<small>{% trans 'Fields with * are required.' %}</small>
{% endif %}

View File

@ -5,7 +5,7 @@
{% endcomment %}
<form method="post" action="{{form.action_url}}" {% for attr_key, attr_val in form.form_attrs.items %} {{attr_key}}="{{attr_val}}"{% endfor %}>
<form method="post" action="" {% for attr_key, attr_val in form.form_attrs.items %} {{attr_key}}="{{attr_val}}"{% endfor %}>
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title">{{form.form_title}}</h5>

View File

@ -10,7 +10,6 @@
$(".{{btn_class}}").each(function () {
$(this).modalForm({
formURL: $(this).data("form-url"),
isDeleteForm: {{modal_reload_page}},
}
);
});