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:
parent
da60ccc85d
commit
6c4ced784b
@ -7,8 +7,7 @@ Created on: 16.11.20
|
|||||||
"""
|
"""
|
||||||
from django.http import HttpRequest
|
from django.http import HttpRequest
|
||||||
|
|
||||||
from konova.settings import HELP_LINK
|
from konova.sub_settings.context_settings import BASE_TITLE, HELP_LINK, BASE_FRONTEND_TITLE
|
||||||
from konova.sub_settings.context_settings import BASE_TITLE, WIKI_URL, BASE_FRONTEND_TITLE
|
|
||||||
|
|
||||||
|
|
||||||
class BaseContext:
|
class BaseContext:
|
||||||
@ -19,11 +18,9 @@ class BaseContext:
|
|||||||
"base_title": BASE_TITLE,
|
"base_title": BASE_TITLE,
|
||||||
"base_frontend_title": BASE_FRONTEND_TITLE,
|
"base_frontend_title": BASE_FRONTEND_TITLE,
|
||||||
"language": "en",
|
"language": "en",
|
||||||
"wiki_url": WIKI_URL,
|
|
||||||
"user": None,
|
"user": None,
|
||||||
"current_role": None,
|
"current_role": None,
|
||||||
"help_link": HELP_LINK,
|
"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 = {}):
|
def __init__(self, request: HttpRequest, additional_context: dict = {}):
|
||||||
|
@ -9,14 +9,15 @@ Created on: 16.11.20
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from bootstrap_modal_forms.forms import BSModalForm
|
from bootstrap_modal_forms.forms import BSModalForm
|
||||||
|
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.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.gis.forms import GeometryField, OSMWidget
|
from django.contrib.gis.forms import GeometryField, OSMWidget
|
||||||
from django.contrib.gis.geos import Polygon
|
from django.contrib.gis.geos import Polygon
|
||||||
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 import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ class BaseForm(forms.Form):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.instance = kwargs.pop("instance", None)
|
self.instance = kwargs.pop("instance", None)
|
||||||
self.user = kwargs.pop("user", None)
|
self.user = kwargs.pop("user", None)
|
||||||
|
self.request = kwargs.pop("request", None)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Check for required fields
|
# Check for required fields
|
||||||
@ -170,25 +172,19 @@ class BaseModalForm(BaseForm, BSModalForm):
|
|||||||
template = self.template
|
template = self.template
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if self.is_valid():
|
if self.is_valid():
|
||||||
self.save()
|
if not is_ajax(request.META):
|
||||||
messages.success(
|
self.save()
|
||||||
request,
|
messages.success(
|
||||||
msg_success
|
|
||||||
)
|
|
||||||
return redirect(redirect_url)
|
|
||||||
else:
|
|
||||||
messages.error(
|
|
||||||
request,
|
|
||||||
msg_error,
|
|
||||||
extra_tags="danger"
|
|
||||||
)
|
|
||||||
for field, error in self.errors.items():
|
|
||||||
messages.error(
|
|
||||||
request,
|
request,
|
||||||
"{}: {}".format(self.fields[field].label, _(error[0])),
|
msg_success
|
||||||
extra_tags="danger"
|
|
||||||
)
|
)
|
||||||
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":
|
elif request.method == "GET":
|
||||||
context = {
|
context = {
|
||||||
"form": self,
|
"form": self,
|
||||||
|
@ -56,9 +56,6 @@ ZB_GROUP = "Registration office"
|
|||||||
ETS_GROUP = "Conservation 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
|
# Needed to redirect to LANIS
|
||||||
## Values to be inserted are [zoom_level, x_coord, y_coord]
|
## 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"
|
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"
|
||||||
|
@ -9,4 +9,4 @@ Created on: 16.11.20
|
|||||||
BASE_TITLE_SHORT = "KSP"
|
BASE_TITLE_SHORT = "KSP"
|
||||||
BASE_TITLE = "KSP - Kompensationsverzeichnis Service Portal"
|
BASE_TITLE = "KSP - Kompensationsverzeichnis Service Portal"
|
||||||
BASE_FRONTEND_TITLE = "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"
|
||||||
|
@ -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!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = [
|
||||||
|
"127.0.0.1",
|
||||||
|
"localhost",
|
||||||
|
]
|
||||||
|
|
||||||
# Authentication settings
|
# Authentication settings
|
||||||
LOGIN_URL = "/login/"
|
LOGIN_URL = "/login/"
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for field in form %}
|
{% for field in form %}
|
||||||
<tr title="{{ field.help_text }}" class="{% if field.errors %}error{% endif %}">
|
<tr title="{{ field.help_text }}" class="{% if field.errors %}alert-danger{% endif %}">
|
||||||
<th scope="row" class="col-sm-3">
|
<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>
|
<label for="id_{{ field.name }}">{{ field.label }}<span class="label-required">{% if field.field.required %}*{% endif %}</span></label>
|
||||||
<small>{{ field.help_text }}</small>
|
<small>{{ field.help_text }}</small>
|
||||||
</th>
|
</th>
|
||||||
<td class="col-sm-9">
|
<td class="col-sm-9">
|
||||||
{{ field }}
|
{{ field }}
|
||||||
{% for error in field.errors %}
|
{% for error in field.errors %}
|
||||||
<strong>{{ error }}</strong>
|
<br>
|
||||||
{% endfor %}
|
<strong class="invalid">{{ error }}</strong>
|
||||||
</td>
|
{% endfor %}
|
||||||
</tr>
|
</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
</tbody>
|
{% endfor %}
|
||||||
</table>
|
</tbody>
|
||||||
{% if form.has_required_fields %}
|
</table>
|
||||||
<small>{% trans 'Fields with * are required.' %}</small>
|
{% if form.has_required_fields %}
|
||||||
{% endif %}
|
<small>{% trans 'Fields with * are required.' %}</small>
|
||||||
|
{% endif %}
|
@ -5,7 +5,7 @@
|
|||||||
{% endcomment %}
|
{% 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 %}
|
{% csrf_token %}
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">{{form.form_title}}</h5>
|
<h5 class="modal-title">{{form.form_title}}</h5>
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
$(".{{btn_class}}").each(function () {
|
$(".{{btn_class}}").each(function () {
|
||||||
$(this).modalForm({
|
$(this).modalForm({
|
||||||
formURL: $(this).data("form-url"),
|
formURL: $(this).data("form-url"),
|
||||||
isDeleteForm: {{modal_reload_page}},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user