From afb0cabec49df4b65f49dfd225a31adb7c98c7cc Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 10 Feb 2022 12:42:41 +0100 Subject: [PATCH] #86 Edit deadline Compensation * adds support for editing of deadlines * adds buttons and urls * adds w-10 as base css-class for all action columns --- .../detail/compensation/includes/actions.html | 2 +- .../compensation/includes/deadlines.html | 7 +++-- .../compensation/includes/states-after.html | 2 +- .../compensation/includes/states-before.html | 2 +- .../eco_account/includes/deadlines.html | 2 +- .../eco_account/includes/deductions.html | 2 +- .../eco_account/includes/documents.html | 2 +- .../eco_account/includes/states-after.html | 2 +- .../eco_account/includes/states-before.html | 2 +- compensation/tests/compensation/test_views.py | 20 +++++++++++++ compensation/urls/compensation.py | 1 + compensation/views/compensation.py | 29 +++++++++++++++++-- .../ema/detail/includes/actions.html | 2 +- .../ema/detail/includes/deadlines.html | 2 +- .../ema/detail/includes/documents.html | 2 +- .../ema/detail/includes/states-after.html | 2 +- .../ema/detail/includes/states-before.html | 2 +- ema/tests/test_views.py | 4 +-- 18 files changed, 68 insertions(+), 19 deletions(-) diff --git a/compensation/templates/compensation/detail/compensation/includes/actions.html b/compensation/templates/compensation/detail/compensation/includes/actions.html index f8a917ee..33037ecf 100644 --- a/compensation/templates/compensation/detail/compensation/includes/actions.html +++ b/compensation/templates/compensation/detail/compensation/includes/actions.html @@ -35,7 +35,7 @@ {% trans 'Comment' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/compensation/templates/compensation/detail/compensation/includes/deadlines.html b/compensation/templates/compensation/detail/compensation/includes/deadlines.html index 0af1498a..7f445657 100644 --- a/compensation/templates/compensation/detail/compensation/includes/deadlines.html +++ b/compensation/templates/compensation/detail/compensation/includes/deadlines.html @@ -54,9 +54,12 @@ {{ deadline.comment }} - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/compensation/templates/compensation/detail/compensation/includes/states-after.html b/compensation/templates/compensation/detail/compensation/includes/states-after.html index c0d8b2d5..2c95ca1a 100644 --- a/compensation/templates/compensation/detail/compensation/includes/states-after.html +++ b/compensation/templates/compensation/detail/compensation/includes/states-after.html @@ -36,7 +36,7 @@ {% trans 'Surface' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/compensation/templates/compensation/detail/compensation/includes/states-before.html b/compensation/templates/compensation/detail/compensation/includes/states-before.html index 50855430..d2ba3697 100644 --- a/compensation/templates/compensation/detail/compensation/includes/states-before.html +++ b/compensation/templates/compensation/detail/compensation/includes/states-before.html @@ -36,7 +36,7 @@ {% trans 'Surface' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/compensation/templates/compensation/detail/eco_account/includes/deadlines.html b/compensation/templates/compensation/detail/eco_account/includes/deadlines.html index ff8a5291..b9d664d4 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/deadlines.html +++ b/compensation/templates/compensation/detail/eco_account/includes/deadlines.html @@ -33,7 +33,7 @@ {% trans 'Comment' %} - + {% trans 'Action' %} diff --git a/compensation/templates/compensation/detail/eco_account/includes/deductions.html b/compensation/templates/compensation/detail/eco_account/includes/deductions.html index 76c116b2..10f177ea 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/deductions.html +++ b/compensation/templates/compensation/detail/eco_account/includes/deductions.html @@ -36,7 +36,7 @@ {% trans 'Created' %} - + {% trans 'Action' %} diff --git a/compensation/templates/compensation/detail/eco_account/includes/documents.html b/compensation/templates/compensation/detail/eco_account/includes/documents.html index e852842b..67881c90 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/documents.html +++ b/compensation/templates/compensation/detail/eco_account/includes/documents.html @@ -33,7 +33,7 @@ {% trans 'Comment' %} - + {% trans 'Action' %} 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 ff074769..bead6f2b 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/states-after.html +++ b/compensation/templates/compensation/detail/eco_account/includes/states-after.html @@ -36,7 +36,7 @@ {% trans 'Surface' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} 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 7b5fe785..c19b4049 100644 --- a/compensation/templates/compensation/detail/eco_account/includes/states-before.html +++ b/compensation/templates/compensation/detail/eco_account/includes/states-before.html @@ -36,7 +36,7 @@ {% trans 'Surface' %} {% if is_default_member and has_access %} - + {% trans 'Action' %} diff --git a/compensation/tests/compensation/test_views.py b/compensation/tests/compensation/test_views.py index 5844e264..27218f2a 100644 --- a/compensation/tests/compensation/test_views.py +++ b/compensation/tests/compensation/test_views.py @@ -8,6 +8,7 @@ Created on: 07.02.22 from django.test.client import Client from django.urls import reverse +from konova.models import Deadline, DeadlineType from konova.settings import DEFAULT_GROUP from konova.tests.test_views import BaseViewTestCase @@ -31,6 +32,13 @@ class CompensationViewTestCase(BaseViewTestCase): action = self.create_dummy_action() self.compensation.actions.set([action]) + self.deadline = Deadline.objects.get_or_create( + type=DeadlineType.FINISHED, + date="2020-01-01", + comment="TESTDEADDLINECOMMENT" + )[0] + self.compensation.deadlines.add(self.deadline) + # Prepare urls self.index_url = reverse("compensation:index", args=()) self.new_url = reverse("compensation:new", args=(self.intervention.id,)) @@ -43,6 +51,8 @@ class CompensationViewTestCase(BaseViewTestCase): self.state_new_url = reverse("compensation:new-state", args=(self.compensation.id,)) self.action_new_url = reverse("compensation:new-action", args=(self.compensation.id,)) self.deadline_new_url = reverse("compensation:new-deadline", args=(self.compensation.id,)) + self.deadline_edit_url = reverse("compensation:deadline-edit", args=(self.compensation.id, self.deadline.id)) + self.deadline_remove_url = reverse("compensation:deadline-remove", args=(self.compensation.id, self.deadline.id)) self.new_doc_url = reverse("compensation:new-doc", args=(self.compensation.id,)) self.state_remove_url = reverse("compensation:state-remove", args=(self.compensation.id, self.comp_state.id,)) @@ -72,6 +82,8 @@ class CompensationViewTestCase(BaseViewTestCase): self.state_new_url, self.action_new_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.state_remove_url, self.action_remove_url, self.new_doc_url, @@ -109,6 +121,8 @@ class CompensationViewTestCase(BaseViewTestCase): self.state_new_url, self.action_new_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.state_remove_url, self.action_remove_url, self.new_doc_url, @@ -147,6 +161,8 @@ class CompensationViewTestCase(BaseViewTestCase): self.state_new_url, self.action_new_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.state_remove_url, self.action_remove_url, self.new_doc_url, @@ -181,6 +197,8 @@ class CompensationViewTestCase(BaseViewTestCase): self.state_new_url, self.action_new_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.state_remove_url, self.action_remove_url, self.new_doc_url, @@ -217,6 +235,8 @@ class CompensationViewTestCase(BaseViewTestCase): self.state_new_url, self.action_new_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.state_remove_url, self.action_remove_url, self.new_doc_url, diff --git a/compensation/urls/compensation.py b/compensation/urls/compensation.py index 3b6a6822..e1a41ff2 100644 --- a/compensation/urls/compensation.py +++ b/compensation/urls/compensation.py @@ -28,6 +28,7 @@ urlpatterns = [ path('/action//remove', action_remove_view, name='action-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('/report', report_view, name='report'), diff --git a/compensation/views/compensation.py b/compensation/views/compensation.py index 65d2ebc5..6dcf442b 100644 --- a/compensation/views/compensation.py +++ b/compensation/views/compensation.py @@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _ from compensation.forms.forms import NewCompensationForm, EditCompensationForm from compensation.forms.modalForms import NewStateModalForm, NewDeadlineModalForm, NewActionModalForm, \ NewCompensationDocumentModalForm, RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, \ - EditCompensationStateModalForm, EditCompensationActionModalForm + EditCompensationStateModalForm, EditCompensationActionModalForm, EditDeadlineModalForm from compensation.models import Compensation, CompensationState, CompensationAction, CompensationDocument from compensation.tables import CompensationTable from intervention.models import Intervention @@ -21,7 +21,8 @@ from konova.utils.generators import generate_qr_code from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \ CHECKED_RECORDED_RESET, COMPENSATION_ADDED_TEMPLATE, COMPENSATION_REMOVED_TEMPLATE, DOCUMENT_ADDED, \ COMPENSATION_STATE_REMOVED, COMPENSATION_STATE_ADDED, COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_ADDED, \ - DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED + DEADLINE_ADDED, DEADLINE_REMOVED, DOCUMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, \ + DEADLINE_EDITED from konova.utils.user_checks import in_group @@ -446,6 +447,30 @@ def deadline_new_view(request: HttpRequest, id: str): ) +@login_required +@default_group_required +@shared_access_required(Compensation, "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(Compensation, 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:detail", args=(id,)) + "#related_data" + ) + + @login_required @default_group_required @shared_access_required(Compensation, "id") diff --git a/ema/templates/ema/detail/includes/actions.html b/ema/templates/ema/detail/includes/actions.html index 30e5e527..02772b36 100644 --- a/ema/templates/ema/detail/includes/actions.html +++ b/ema/templates/ema/detail/includes/actions.html @@ -33,7 +33,7 @@ {% trans 'Comment' %} - + {% trans 'Action' %} diff --git a/ema/templates/ema/detail/includes/deadlines.html b/ema/templates/ema/detail/includes/deadlines.html index 6c7214e4..761ce067 100644 --- a/ema/templates/ema/detail/includes/deadlines.html +++ b/ema/templates/ema/detail/includes/deadlines.html @@ -33,7 +33,7 @@ {% trans 'Comment' %} - + {% trans 'Action' %} diff --git a/ema/templates/ema/detail/includes/documents.html b/ema/templates/ema/detail/includes/documents.html index 7be632d3..b38d5499 100644 --- a/ema/templates/ema/detail/includes/documents.html +++ b/ema/templates/ema/detail/includes/documents.html @@ -33,7 +33,7 @@ {% trans 'Comment' %} - + {% trans 'Action' %} diff --git a/ema/templates/ema/detail/includes/states-after.html b/ema/templates/ema/detail/includes/states-after.html index e876a166..e09f4ba5 100644 --- a/ema/templates/ema/detail/includes/states-after.html +++ b/ema/templates/ema/detail/includes/states-after.html @@ -35,7 +35,7 @@ {% trans 'Surface' %} - + {% trans 'Action' %} diff --git a/ema/templates/ema/detail/includes/states-before.html b/ema/templates/ema/detail/includes/states-before.html index aec3f328..1369829b 100644 --- a/ema/templates/ema/detail/includes/states-before.html +++ b/ema/templates/ema/detail/includes/states-before.html @@ -35,7 +35,7 @@ {% trans 'Surface' %} - + {% trans 'Action' %} diff --git a/ema/tests/test_views.py b/ema/tests/test_views.py index 229f8841..9654e8f3 100644 --- a/ema/tests/test_views.py +++ b/ema/tests/test_views.py @@ -63,11 +63,11 @@ class EmaViewTestCase(CompensationViewTestCase): self.action_edit_url = reverse("ema:action-edit", args=(self.ema.id, action.id)) self.action_remove_url = reverse("ema:action-remove", args=(self.ema.id, action.id,)) - self.deadline = Deadline.objects.create( + self.deadline = Deadline.objects.get_or_create( type=DeadlineType.FINISHED, date="2020-01-01", comment="TESTCOMMENT", - ) + )[0] self.ema.deadlines.add(self.deadline) self.deadline_new_url = reverse("ema:new-deadline", args=(self.ema.id,))