#7 New Form
* adds creation of new compensation directly from intervention detail view * adds comment rendering on compensation detail view (WIP) * adds shared_access_required decorator * adds/updates translations
This commit is contained in:
parent
b7ef6ff006
commit
a50deaaf18
@ -11,8 +11,9 @@ from compensation.views.compensation_views import *
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Main compensation
|
# Main compensation
|
||||||
path("", index_view, name="index"),
|
path("", index_view, name="index"),
|
||||||
path('new', new_view, name='new'),
|
|
||||||
path('new/id', new_id_view, name='new-id'),
|
path('new/id', new_id_view, name='new-id'),
|
||||||
|
path('new/<intervention_id>', new_view, name='new'),
|
||||||
|
path('new', new_view, name='new'),
|
||||||
path('<id>', open_view, name='open'),
|
path('<id>', open_view, name='open'),
|
||||||
path('<id>/log', log_view, name='log'),
|
path('<id>/log', log_view, name='log'),
|
||||||
path('<id>/edit', edit_view, name='edit'),
|
path('<id>/edit', edit_view, name='edit'),
|
||||||
|
@ -92,8 +92,19 @@ class NewCompensationForm(BaseForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
intervention_id = kwargs.pop("intervention_id", None)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.form_title = _("New compensation")
|
self.form_title = _("New compensation")
|
||||||
|
|
||||||
|
# If the compensation shall directly be initialized from an intervention, we need to fill in the intervention id
|
||||||
|
# and disable the form field.
|
||||||
|
# Furthermore the action_url needs to be set accordingly.
|
||||||
|
if intervention_id is not None:
|
||||||
|
self.initialize_form_field("intervention", intervention_id)
|
||||||
|
self.disable_form_field("intervention")
|
||||||
|
self.action_url = reverse("compensation:new", args=(intervention_id,))
|
||||||
|
self.cancel_redirect = reverse("intervention:open", args=(intervention_id,))
|
||||||
|
else:
|
||||||
self.action_url = reverse("compensation:new")
|
self.action_url = reverse("compensation:new")
|
||||||
self.cancel_redirect = reverse("compensation:index")
|
self.cancel_redirect = reverse("compensation:index")
|
||||||
|
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
{% load i18n fontawesome_5 %}
|
||||||
|
|
||||||
|
{% if intervention.comment %}
|
||||||
|
<div class="w-100">
|
||||||
|
<div class="card mt-3">
|
||||||
|
<div class="card-header rlp-r">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12 col-md-12 col-lg-12">
|
||||||
|
<h5 class="card-title">
|
||||||
|
{% fa5_icon 'info-circle' %}
|
||||||
|
{% trans 'Comment' %}
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-text font-italic">
|
||||||
|
{{obj.comment}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
@ -99,8 +99,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
<div class="col-sm-12 col-md-12 col-lg-6">
|
||||||
|
<div class="row">
|
||||||
{% include 'map/geom_form.html' %}
|
{% include 'map/geom_form.html' %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
{% include 'compensation/detail/compensation/includes/comment.html' %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ from compensation.forms.forms import NewCompensationForm
|
|||||||
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm
|
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm
|
||||||
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
|
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
|
||||||
from compensation.tables import CompensationTable
|
from compensation.tables import CompensationTable
|
||||||
|
from intervention.models import Intervention
|
||||||
from konova.contexts import BaseContext
|
from konova.contexts import BaseContext
|
||||||
from konova.decorators import *
|
from konova.decorators import *
|
||||||
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm
|
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm
|
||||||
@ -46,7 +47,8 @@ def index_view(request: HttpRequest):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
def new_view(request: HttpRequest):
|
@shared_access_required(Intervention, "intervention_id")
|
||||||
|
def new_view(request: HttpRequest, intervention_id: str = None):
|
||||||
"""
|
"""
|
||||||
Renders a view for a new compensation creation
|
Renders a view for a new compensation creation
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ def new_view(request: HttpRequest):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
template = "compensation/new/view.html"
|
template = "compensation/new/view.html"
|
||||||
data_form = NewCompensationForm(request.POST or None)
|
data_form = NewCompensationForm(request.POST or None, intervention_id=intervention_id)
|
||||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False)
|
geom_form = SimpleGeomForm(request.POST or None, read_only=False)
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if data_form.is_valid() and geom_form.is_valid():
|
if data_form.is_valid() and geom_form.is_valid():
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
{% load i18n fontawesome_5 %}
|
{% load i18n fontawesome_5 %}
|
||||||
|
|
||||||
{% if intervention.comment %}
|
{% if intervention.comment %}
|
||||||
<div class="card mt-3">
|
<div class="w-100">
|
||||||
|
<div class="card mt-3">
|
||||||
<div class="card-header rlp-r">
|
<div class="card-header rlp-r">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12 col-md-12 col-lg-12">
|
<div class="col-sm-12 col-md-12 col-lg-12">
|
||||||
@ -17,5 +18,6 @@
|
|||||||
{{intervention.comment}}
|
{{intervention.comment}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
@ -11,7 +11,7 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="d-flex justify-content-end">
|
<div class="d-flex justify-content-end">
|
||||||
{% if is_default_member and has_access %}
|
{% if is_default_member and has_access %}
|
||||||
<a href="{% url 'compensation:new' %}" title="{% trans 'Add new compensation' %}">
|
<a href="{% url 'compensation:new' intervention.id %}" title="{% trans 'Add new compensation' %}">
|
||||||
<button class="btn btn-outline-default">
|
<button class="btn btn-outline-default">
|
||||||
{% fa5_icon 'plus' %}
|
{% fa5_icon 'plus' %}
|
||||||
{% fa5_icon 'leaf' %}
|
{% fa5_icon 'leaf' %}
|
||||||
|
@ -9,11 +9,12 @@ Created on: 16.11.20
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect, get_object_or_404
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from konova.settings import DEFAULT_GROUP, ETS_GROUP, ZB_GROUP
|
from konova.settings import DEFAULT_GROUP, ETS_GROUP, ZB_GROUP
|
||||||
|
from konova.utils.message_templates import MISSING_GROUP_PERMISSION, DATA_UNSHARED
|
||||||
|
|
||||||
|
|
||||||
def staff_required(function):
|
def staff_required(function):
|
||||||
@ -80,7 +81,7 @@ def default_group_required(function):
|
|||||||
if has_group:
|
if has_group:
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
messages.info(request, _("You need to be part of another user group."))
|
messages.info(request, MISSING_GROUP_PERMISSION)
|
||||||
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ def registration_office_group_required(function):
|
|||||||
if has_group:
|
if has_group:
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
messages.info(request, _("You need to be part of another user group."))
|
messages.info(request, MISSING_GROUP_PERMISSION)
|
||||||
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
@ -120,6 +121,35 @@ def conservation_office_group_required(function):
|
|||||||
if has_group:
|
if has_group:
|
||||||
return function(request, *args, **kwargs)
|
return function(request, *args, **kwargs)
|
||||||
else:
|
else:
|
||||||
messages.info(request, _("You need to be part of another user group."))
|
messages.info(request, MISSING_GROUP_PERMISSION)
|
||||||
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
|
||||||
|
def shared_access_required(obj_class, id_key):
|
||||||
|
""" Checks whether the data is shared with the requesting user
|
||||||
|
|
||||||
|
Args:
|
||||||
|
obj_class (Model): The object/model class
|
||||||
|
id_key (str): The name of the identifier attribute in **kwargs
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
def decorator(function):
|
||||||
|
@wraps(function)
|
||||||
|
def wrap(request, *args, **kwargs):
|
||||||
|
user = request.user
|
||||||
|
_id = kwargs.get(id_key, None)
|
||||||
|
if _id is not None:
|
||||||
|
obj = get_object_or_404(obj_class, id=_id)
|
||||||
|
is_shared = obj.is_shared_with(user)
|
||||||
|
if not is_shared:
|
||||||
|
messages.info(
|
||||||
|
request,
|
||||||
|
DATA_UNSHARED
|
||||||
|
)
|
||||||
|
return redirect("home")
|
||||||
|
return function(request, *args, **kwargs)
|
||||||
|
return wrap
|
||||||
|
return decorator
|
@ -11,3 +11,5 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
FORM_INVALID = _("There was an error on this form.")
|
FORM_INVALID = _("There was an error on this form.")
|
||||||
INTERVENTION_INVALID = _("There are errors in this intervention.")
|
INTERVENTION_INVALID = _("There are errors in this intervention.")
|
||||||
IDENTIFIER_REPLACED = _("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier")
|
IDENTIFIER_REPLACED = _("The identifier '{}' had to be changed to '{}' since another entry has been added in the meanwhile, which uses this identifier")
|
||||||
|
DATA_UNSHARED = _("This data is not shared with you")
|
||||||
|
MISSING_GROUP_PERMISSION = _("You need to be part of another user group.")
|
Binary file not shown.
@ -85,7 +85,7 @@ msgstr "Eingriff"
|
|||||||
|
|
||||||
#: compensation/forms/forms.py:65
|
#: compensation/forms/forms.py:65
|
||||||
msgid "Fundings"
|
msgid "Fundings"
|
||||||
msgstr ""
|
msgstr "Förderungen"
|
||||||
|
|
||||||
#: compensation/forms/forms.py:68
|
#: compensation/forms/forms.py:68
|
||||||
msgid "Select fundings for this compensation"
|
msgid "Select fundings for this compensation"
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
|
|
||||||
{% if geom_form.empty %}
|
{% if geom_form.empty %}
|
||||||
|
<div class="w-100">
|
||||||
<div class="alert alert-info">{% trans 'No geometry added, yet.' %}</div>
|
<div class="alert alert-info">{% trans 'No geometry added, yet.' %}</div>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{geom_form.media}}
|
{{geom_form.media}}
|
||||||
{{geom_form.geom}}
|
{{geom_form.geom}}
|
Loading…
Reference in New Issue
Block a user