* 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:
mipel
2021-10-04 13:23:14 +02:00
parent b7ef6ff006
commit a50deaaf18
12 changed files with 104 additions and 26 deletions

View File

@@ -11,8 +11,9 @@ from compensation.views.compensation_views import *
urlpatterns = [
# Main compensation
path("", index_view, name="index"),
path('new', new_view, name='new'),
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>/log', log_view, name='log'),
path('<id>/edit', edit_view, name='edit'),

View File

@@ -92,10 +92,21 @@ class NewCompensationForm(BaseForm):
)
def __init__(self, *args, **kwargs):
intervention_id = kwargs.pop("intervention_id", None)
super().__init__(*args, **kwargs)
self.form_title = _("New compensation")
self.action_url = reverse("compensation:new")
self.cancel_redirect = reverse("compensation:index")
# 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.cancel_redirect = reverse("compensation:index")
tmp = Compensation()
identifier = tmp._generate_new_identifier()

View File

@@ -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 %}

View File

@@ -99,7 +99,12 @@
</div>
</div>
<div class="col-sm-12 col-md-12 col-lg-6">
{% include 'map/geom_form.html' %}
<div class="row">
{% include 'map/geom_form.html' %}
</div>
<div class="row">
{% include 'compensation/detail/compensation/includes/comment.html' %}
</div>
</div>
</div>
<hr>

View File

@@ -8,6 +8,7 @@ from compensation.forms.forms import NewCompensationForm
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
from compensation.tables import CompensationTable
from intervention.models import Intervention
from konova.contexts import BaseContext
from konova.decorators import *
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm
@@ -46,7 +47,8 @@ def index_view(request: HttpRequest):
@login_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
@@ -57,7 +59,7 @@ def new_view(request: HttpRequest):
"""
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)
if request.method == "POST":
if data_form.is_valid() and geom_form.is_valid():