From aa242e040aa5078a60fd27e7bbe9702f13a6d734 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 10 Feb 2022 11:15:01 +0100 Subject: [PATCH] #86 Edit states EMA/EcoAccount * adds support for editing of states for EMA and EcoAccount * adds buttons and urls --- .../eco_account/includes/states-after.html | 7 +++-- .../eco_account/includes/states-before.html | 7 +++-- compensation/urls/eco_account.py | 1 + compensation/views/eco_account.py | 29 +++++++++++++++++-- .../ema/detail/includes/states-after.html | 7 +++-- .../ema/detail/includes/states-before.html | 7 +++-- ema/urls.py | 1 + ema/views.py | 28 ++++++++++++++++-- 8 files changed, 75 insertions(+), 12 deletions(-) diff --git a/compensation/templates/compensation/detail/eco_account/includes/states-after.html b/compensation/templates/compensation/detail/eco_account/includes/states-after.html index ea696b31..ff074769 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/states-after.html +++ b/compensation/templates/compensation/detail/eco_account/includes/states-after.html @@ -57,9 +57,12 @@ {% endif %} {{ state.surface|floatformat:2 }} m² - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/compensation/templates/compensation/detail/eco_account/includes/states-before.html b/compensation/templates/compensation/detail/eco_account/includes/states-before.html index af3042ea..7b5fe785 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/states-before.html +++ b/compensation/templates/compensation/detail/eco_account/includes/states-before.html @@ -57,9 +57,12 @@ {% endif %} {{ state.surface|floatformat:2 }} m² - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/compensation/urls/eco_account.py b/compensation/urls/eco_account.py index e390d4fb..f23f2a11 100644 --- a/compensation/urls/eco_account.py +++ b/compensation/urls/eco_account.py @@ -22,6 +22,7 @@ urlpatterns = [ path('/state/new', state_new_view, name='new-state'), path('/action/new', action_new_view, name='new-action'), path('/state//remove', state_remove_view, name='state-remove'), + path('/state//edit', state_edit_view, name='state-edit'), path('/action//remove', action_remove_view, name='action-remove'), path('/deadline//remove', deadline_remove_view, name='deadline-remove'), path('/deadline/new', deadline_new_view, name="new-deadline"), diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index 19959f81..a0365068 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -16,7 +16,8 @@ from django.shortcuts import render, get_object_or_404, redirect from compensation.forms.forms import NewEcoAccountForm, EditEcoAccountForm from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm, \ - NewEcoAccountDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm + NewEcoAccountDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, \ + EditCompensationStateModalForm from compensation.models import EcoAccount, EcoAccountDocument, CompensationState, CompensationAction from compensation.tables import EcoAccountTable from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm, RemoveEcoAccountDeductionModalForm, \ @@ -34,7 +35,7 @@ from konova.utils.generators import generate_qr_code from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ CANCEL_ACC_RECORDED_OR_DEDUCTED, DEDUCTION_REMOVED, DEDUCTION_ADDED, DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, \ COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, \ - DEDUCTION_EDITED, DOCUMENT_EDITED + DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED from konova.utils.user_checks import in_group @@ -442,6 +443,30 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str): ) +@login_required +@default_group_required +@shared_access_required(EcoAccount, "id") +def state_edit_view(request: HttpRequest, id: str, state_id: str): + """ Renders a form for editing a compensation state + + Args: + request (HttpRequest): The incoming request + id (str): The compensation's id + state_id (str): The state's id + + Returns: + + """ + acc = get_object_or_404(EcoAccount, id=id) + state = get_object_or_404(CompensationState, id=state_id) + form = EditCompensationStateModalForm(request.POST or None, instance=acc, state=state, request=request) + return form.process_request( + request, + msg_success=COMPENSATION_STATE_EDITED, + redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data" + ) + + @login_required @default_group_required @shared_access_required(EcoAccount, "id") diff --git a/ema/templates/ema/detail/includes/states-after.html b/ema/templates/ema/detail/includes/states-after.html index f0d3dfc4..e876a166 100644 --- a/ema/templates/ema/detail/includes/states-after.html +++ b/ema/templates/ema/detail/includes/states-after.html @@ -55,9 +55,12 @@ {% endif %} {{ state.surface|floatformat:2 }} m² - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/ema/templates/ema/detail/includes/states-before.html b/ema/templates/ema/detail/includes/states-before.html index f479bd8d..aec3f328 100644 --- a/ema/templates/ema/detail/includes/states-before.html +++ b/ema/templates/ema/detail/includes/states-before.html @@ -55,9 +55,12 @@ {% endif %} {{ state.surface|floatformat:2 }} m² - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/ema/urls.py b/ema/urls.py index a2ee618f..4008a69c 100644 --- a/ema/urls.py +++ b/ema/urls.py @@ -22,6 +22,7 @@ urlpatterns = [ path('/state/new', state_new_view, name='new-state'), path('/action/new', action_new_view, name='new-action'), path('/state//remove', state_remove_view, name='state-remove'), + path('/state//edit', state_edit_view, name='state-edit'), path('/action//remove', action_remove_view, name='action-remove'), path('/deadline//remove', deadline_remove_view, name='deadline-remove'), path('/deadline/new', deadline_new_view, name="new-deadline"), diff --git a/ema/views.py b/ema/views.py index 0650f4c9..bc54631c 100644 --- a/ema/views.py +++ b/ema/views.py @@ -7,7 +7,7 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm, \ - RemoveCompensationActionModalForm, RemoveCompensationStateModalForm + RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, EditCompensationStateModalForm from compensation.models import CompensationAction, CompensationState from ema.forms import NewEmaForm, EditEmaForm, NewEmaDocumentModalForm from ema.tables import EmaTable @@ -24,7 +24,7 @@ from konova.utils.documents import get_document, remove_document from konova.utils.generators import generate_qr_code from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID, DATA_UNSHARED, DATA_UNSHARED_EXPLANATION, \ DOCUMENT_ADDED, COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, \ - COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED + COMPENSATION_ACTION_ADDED, DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED from konova.utils.user_checks import in_group @@ -460,6 +460,30 @@ def state_remove_view(request: HttpRequest, id: str, state_id: str): ) +@login_required +@conservation_office_group_required +@shared_access_required(Ema, "id") +def state_edit_view(request: HttpRequest, id: str, state_id: str): + """ Renders a form for editing an EMA state + + Args: + request (HttpRequest): The incoming request + id (str): The ema id + state_id (str): The state's id + + Returns: + + """ + ema = get_object_or_404(Ema, id=id) + state = get_object_or_404(CompensationState, id=state_id) + form = EditCompensationStateModalForm(request.POST or None, instance=ema, state=state, request=request) + return form.process_request( + request, + msg_success=COMPENSATION_STATE_EDITED, + redirect_url=reverse("ema:detail", args=(id,)) + "#related_data" + ) + + @login_required @conservation_office_group_required @shared_access_required(Ema, "id")