* links edit button in detail view with edit functionality
* fixes minor comment rendering bug
* fixes bug where compensation changes won't save
This commit is contained in:
mipel 2021-10-04 16:18:59 +02:00
parent feeddda90d
commit 0342d96a1f
5 changed files with 38 additions and 7 deletions

View File

@ -196,6 +196,7 @@ class EditCompensationForm(NewCompensationForm):
self.instance.geometry = geometry self.instance.geometry = geometry
self.instance.comment = comment self.instance.comment = comment
self.instance.fundings.set(fundings) self.instance.fundings.set(fundings)
self.instance.save()
self.instance.log.add(action) self.instance.log.add(action)
return self.instance return self.instance

View File

@ -1,6 +1,6 @@
{% load i18n fontawesome_5 %} {% load i18n fontawesome_5 %}
{% if intervention.comment %} {% if obj.comment %}
<div class="w-100"> <div class="w-100">
<div class="card mt-3"> <div class="card mt-3">
<div class="card-header rlp-r"> <div class="card-header rlp-r">

View File

@ -13,7 +13,7 @@
</a> </a>
{% if has_access %} {% if has_access %}
{% if is_default_member %} {% if is_default_member %}
<a href="{% url 'home' %}" class="mr-2"> <a href="{% url 'compensation:edit' obj.id %}" class="mr-2">
<button class="btn btn-default" title="{% trans 'Edit' %}"> <button class="btn btn-default" title="{% trans 'Edit' %}">
{% fa5_icon 'edit' %} {% fa5_icon 'edit' %}
</button> </button>

View File

@ -75,7 +75,7 @@
</div> </div>
<br> <br>
{% empty %} {% empty %}
None {% trans 'None' %}
{% endfor %} {% endfor %}
</td> </td>
</tr> </tr>

View File

@ -1,10 +1,10 @@
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.db.models import Sum from django.db.models import Sum
from django.http import HttpRequest, JsonResponse from django.http import HttpRequest, JsonResponse
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from compensation.forms.forms import NewCompensationForm from compensation.forms.forms import NewCompensationForm, EditCompensationForm
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
@ -110,8 +110,38 @@ def new_id_view(request: HttpRequest):
@login_required @login_required
@default_group_required @default_group_required
def edit_view(request: HttpRequest, id: str): def edit_view(request: HttpRequest, id: str):
# ToDo """
pass Renders a view for editing compensations
Args:
request (HttpRequest): The incoming request
Returns:
"""
template = "compensation/new/view.html"
# Get object from db
comp = get_object_or_404(Compensation, id=id)
# Create forms, initialize with values from db/from POST request
data_form = EditCompensationForm(request.POST or None, instance=comp)
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=comp)
if request.method == "POST":
if data_form.is_valid() and geom_form.is_valid():
# The data form takes the geom form for processing, as well as the performing user
comp = data_form.save(request.user, geom_form)
messages.success(request, _("Compensation {} edited").format(comp.identifier))
return redirect("compensation:open", id=comp.id)
else:
messages.error(request, FORM_INVALID)
else:
# For clarification: nothing in this case
pass
context = {
"form": data_form,
"geom_form": geom_form,
}
context = BaseContext(request, context).context
return render(request, template, context)
@login_required @login_required