diff --git a/compensation/forms/forms.py b/compensation/forms/forms.py index 292dce91..268ab4b7 100644 --- a/compensation/forms/forms.py +++ b/compensation/forms/forms.py @@ -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 \ No newline at end of file diff --git a/compensation/templates/compensation/detail/compensation/includes/comment.html b/compensation/templates/compensation/detail/compensation/includes/comment.html index b29552e9..4f3243b5 100644 --- a/compensation/templates/compensation/detail/compensation/includes/comment.html +++ b/compensation/templates/compensation/detail/compensation/includes/comment.html @@ -1,6 +1,6 @@ {% load i18n fontawesome_5 %} -{% if intervention.comment %} +{% if obj.comment %}
diff --git a/compensation/templates/compensation/detail/compensation/includes/controls.html b/compensation/templates/compensation/detail/compensation/includes/controls.html index 0f5149a5..5d6f61be 100644 --- a/compensation/templates/compensation/detail/compensation/includes/controls.html +++ b/compensation/templates/compensation/detail/compensation/includes/controls.html @@ -13,7 +13,7 @@ {% if has_access %} {% if is_default_member %} - + diff --git a/compensation/templates/compensation/detail/compensation/view.html b/compensation/templates/compensation/detail/compensation/view.html index 20dafe75..487f2742 100644 --- a/compensation/templates/compensation/detail/compensation/view.html +++ b/compensation/templates/compensation/detail/compensation/view.html @@ -75,7 +75,7 @@

{% empty %} - None + {% trans 'None' %} {% endfor %} diff --git a/compensation/views/compensation_views.py b/compensation/views/compensation_views.py index 65d813df..be1b843b 100644 --- a/compensation/views/compensation_views.py +++ b/compensation/views/compensation_views.py @@ -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 - 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