From 6fbdc3c1fb5ff340e4ed2f4fc58c5ea55b5edcbd Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 10 Feb 2022 12:49:30 +0100 Subject: [PATCH] #86 Edit deadlines EcoAccount * adds support for editing of deadlines in EcoAccount * adds buttons and urls --- .../eco_account/includes/deadlines.html | 7 +++-- compensation/tests/ecoaccount/test_views.py | 19 +++++++++++++ compensation/urls/eco_account.py | 4 ++- compensation/views/eco_account.py | 28 +++++++++++++++++-- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/compensation/templates/compensation/detail/eco_account/includes/deadlines.html b/compensation/templates/compensation/detail/eco_account/includes/deadlines.html index b9d664d4..beaecfda 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/deadlines.html +++ b/compensation/templates/compensation/detail/eco_account/includes/deadlines.html @@ -52,9 +52,12 @@ {{ deadline.comment }} - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/compensation/tests/ecoaccount/test_views.py b/compensation/tests/ecoaccount/test_views.py index 091e86db..617f7437 100644 --- a/compensation/tests/ecoaccount/test_views.py +++ b/compensation/tests/ecoaccount/test_views.py @@ -9,6 +9,7 @@ from django.urls import reverse from django.test import Client from compensation.tests.compensation.test_views import CompensationViewTestCase +from konova.models import DeadlineType, Deadline from konova.settings import DEFAULT_GROUP @@ -53,7 +54,17 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.action_edit_url = reverse("compensation:acc:action-edit", args=(self.eco_account.id, self.comp_action.id)) self.action_remove_url = reverse("compensation:acc:action-remove", args=(self.eco_account.id, self.comp_action.id,)) + self.deadline = Deadline.objects.get_or_create( + type=DeadlineType.FINISHED, + date="2020-01-01", + comment="DEADLINE COMMENT" + )[0] + self.eco_account.deadlines.add(self.deadline) + self.deadline_new_url = reverse("compensation:acc:new-deadline", args=(self.eco_account.id,)) + self.deadline_edit_url = reverse("compensation:acc:deadline-edit", args=(self.eco_account.id, self.deadline.id)) + self.deadline_remove_url = reverse("compensation:acc:deadline-remove", args=(self.eco_account.id, self.deadline.id)) + self.new_doc_url = reverse("compensation:acc:new-doc", args=(self.eco_account.id,)) def test_logged_in_no_groups_shared(self): @@ -89,6 +100,8 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.action_edit_url, self.action_remove_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.new_doc_url, ] @@ -128,6 +141,8 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.action_edit_url, self.action_remove_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.new_doc_url, ] @@ -165,6 +180,8 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.action_remove_url, self.new_doc_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.log_url, self.remove_url, ] @@ -204,6 +221,8 @@ class EcoAccountViewTestCase(CompensationViewTestCase): self.log_url, self.remove_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, ] self.assert_url_fail(client, fail_urls) self.assert_url_success(client, success_urls) diff --git a/compensation/urls/eco_account.py b/compensation/urls/eco_account.py index ccd549dd..a3d1aa38 100644 --- a/compensation/urls/eco_account.py +++ b/compensation/urls/eco_account.py @@ -28,8 +28,10 @@ urlpatterns = [ path('/action//edit', action_edit_view, name='action-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"), + path('/deadline//edit', deadline_edit_view, name='deadline-edit'), + path('/deadline//remove', deadline_remove_view, name='deadline-remove'), + path('/share/', share_view, name='share'), path('/share', create_share_view, name='share-create'), diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index 37223786..cf5f3288 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -17,7 +17,7 @@ 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, \ - EditCompensationStateModalForm, EditCompensationActionModalForm + EditCompensationStateModalForm, EditCompensationActionModalForm, EditDeadlineModalForm from compensation.models import EcoAccount, EcoAccountDocument, CompensationState, CompensationAction from compensation.tables import EcoAccountTable from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm, RemoveEcoAccountDeductionModalForm, \ @@ -35,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, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED + DEDUCTION_EDITED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED from konova.utils.user_checks import in_group @@ -515,6 +515,30 @@ def action_edit_view(request: HttpRequest, id: str, action_id: str): ) +@login_required +@default_group_required +@shared_access_required(EcoAccount, "id") +def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str): + """ Renders a form for editing deadlines from a compensation + + Args: + request (HttpRequest): The incoming request + id (str): The compensation's id + deadline_id (str): The deadline's id + + Returns: + + """ + comp = get_object_or_404(EcoAccount, id=id) + deadline = get_object_or_404(Deadline, id=deadline_id) + form = EditDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request) + return form.process_request( + request, + msg_success=DEADLINE_EDITED, + redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data" + ) + + @login_required @default_group_required @shared_access_required(EcoAccount, "id")