#7 New Form
* 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:
parent
d0aa125248
commit
46e1a9af86
@ -196,6 +196,7 @@ class EditCompensationForm(NewCompensationForm):
|
||||
self.instance.geometry = geometry
|
||||
self.instance.comment = comment
|
||||
self.instance.fundings.set(fundings)
|
||||
self.instance.save()
|
||||
|
||||
self.instance.log.add(action)
|
||||
return self.instance
|
@ -1,6 +1,6 @@
|
||||
{% load i18n fontawesome_5 %}
|
||||
|
||||
{% if intervention.comment %}
|
||||
{% if obj.comment %}
|
||||
<div class="w-100">
|
||||
<div class="card mt-3">
|
||||
<div class="card-header rlp-r">
|
||||
|
@ -13,7 +13,7 @@
|
||||
</a>
|
||||
{% if has_access %}
|
||||
{% 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' %}">
|
||||
{% fa5_icon 'edit' %}
|
||||
</button>
|
||||
|
@ -75,7 +75,7 @@
|
||||
</div>
|
||||
<br>
|
||||
{% empty %}
|
||||
None
|
||||
{% trans 'None' %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -1,10 +1,10 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Sum
|
||||
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 compensation.forms.forms import NewCompensationForm
|
||||
from compensation.forms.forms import NewCompensationForm, EditCompensationForm
|
||||
from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm
|
||||
from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument
|
||||
from compensation.tables import CompensationTable
|
||||
@ -110,8 +110,38 @@ def new_id_view(request: HttpRequest):
|
||||
@login_required
|
||||
@default_group_required
|
||||
def edit_view(request: HttpRequest, id: str):
|
||||
# ToDo
|
||||
"""
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user