diff --git a/compensation/forms/modalForms.py b/compensation/forms/modalForms.py index 6436a7c8..804ebad4 100644 --- a/compensation/forms/modalForms.py +++ b/compensation/forms/modalForms.py @@ -21,7 +21,7 @@ from konova.contexts import BaseContext from konova.forms import BaseModalForm, NewDocumentModalForm, RemoveModalForm from konova.models import DeadlineType from konova.utils.message_templates import FORM_INVALID, ADDED_COMPENSATION_STATE, ADDED_DEADLINE, \ - ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED + ADDED_COMPENSATION_ACTION, PAYMENT_EDITED, COMPENSATION_STATE_EDITED, COMPENSATION_ACTION_EDITED, DEADLINE_EDITED class NewPaymentForm(BaseModalForm): @@ -373,6 +373,29 @@ class NewDeadlineModalForm(BaseModalForm): return deadline +class EditDeadlineModalForm(NewDeadlineModalForm): + deadline = None + + def __init__(self, *args, **kwargs): + self.deadline = kwargs.pop("deadline", None) + super().__init__(*args, **kwargs) + form_data = { + "type": self.deadline.type, + "date": str(self.deadline.date), + "comment": self.deadline.comment, + } + self.load_initial_data(form_data) + + def save(self): + deadline = self.deadline + deadline.type = self.cleaned_data.get("type", None) + deadline.date = self.cleaned_data.get("date", None) + deadline.comment = self.cleaned_data.get("comment", None) + deadline.save() + self.instance.mark_as_edited(self.user, self.request, edit_comment=DEADLINE_EDITED) + return deadline + + class NewActionModalForm(BaseModalForm): """ Form handling action related input diff --git a/ema/templates/ema/detail/includes/deadlines.html b/ema/templates/ema/detail/includes/deadlines.html index 02efaf8b..6c7214e4 100644 --- a/ema/templates/ema/detail/includes/deadlines.html +++ b/ema/templates/ema/detail/includes/deadlines.html @@ -52,9 +52,12 @@ {{ deadline.comment }} - + {% if is_default_member and has_access %} - + {% endif %} diff --git a/ema/tests/test_views.py b/ema/tests/test_views.py index 70090c7d..229f8841 100644 --- a/ema/tests/test_views.py +++ b/ema/tests/test_views.py @@ -13,7 +13,7 @@ from django.test.client import Client from compensation.tests.compensation.test_views import CompensationViewTestCase from ema.models import Ema from intervention.models import Responsibility -from konova.models import Geometry +from konova.models import Geometry, Deadline, DeadlineType from konova.settings import DEFAULT_GROUP, ETS_GROUP from user.models import UserActionLogEntry @@ -63,7 +63,16 @@ 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( + type=DeadlineType.FINISHED, + date="2020-01-01", + comment="TESTCOMMENT", + ) + self.ema.deadlines.add(self.deadline) + self.deadline_new_url = reverse("ema:new-deadline", args=(self.ema.id,)) + self.deadline_edit_url = reverse("ema:deadline-edit", args=(self.ema.id, self.deadline.id)) + self.deadline_remove_url = reverse("ema:deadline-remove", args=(self.ema.id, self.deadline.id)) def create_dummy_data(self): # Create dummy data @@ -116,6 +125,8 @@ class EmaViewTestCase(CompensationViewTestCase): self.state_remove_url, self.state_edit_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.action_edit_url, self.action_remove_url, self.action_new_url, @@ -167,6 +178,8 @@ class EmaViewTestCase(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, self.log_url, self.remove_url, @@ -203,6 +216,8 @@ class EmaViewTestCase(CompensationViewTestCase): self.state_edit_url, self.state_remove_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.action_new_url, self.action_edit_url, self.action_remove_url, @@ -243,6 +258,8 @@ class EmaViewTestCase(CompensationViewTestCase): self.state_edit_url, self.state_remove_url, self.deadline_new_url, + self.deadline_edit_url, + self.deadline_remove_url, self.action_new_url, self.action_edit_url, self.action_remove_url, diff --git a/ema/urls.py b/ema/urls.py index 3e7092c6..90cafb66 100644 --- a/ema/urls.py +++ b/ema/urls.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/ema/views.py b/ema/views.py index 607d58df..e9d0acb6 100644 --- a/ema/views.py +++ b/ema/views.py @@ -8,7 +8,7 @@ from django.utils.translation import gettext_lazy as _ from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm, \ RemoveCompensationActionModalForm, RemoveCompensationStateModalForm, EditCompensationStateModalForm, \ - EditCompensationActionModalForm + EditCompensationActionModalForm, EditDeadlineModalForm from compensation.models import CompensationAction, CompensationState from ema.forms import NewEmaForm, EditEmaForm, NewEmaDocumentModalForm from ema.tables import EmaTable @@ -26,7 +26,7 @@ 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_STATE_EDITED, \ - COMPENSATION_ACTION_EDITED + COMPENSATION_ACTION_EDITED, DEADLINE_EDITED from konova.utils.user_checks import in_group @@ -653,6 +653,30 @@ def create_share_view(request: HttpRequest, id: str): ) +@login_required +@conservation_office_group_required +@shared_access_required(Ema, "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: + + """ + ema = get_object_or_404(Ema, id=id) + deadline = get_object_or_404(Deadline, id=deadline_id) + form = EditDeadlineModalForm(request.POST or None, instance=ema, deadline=deadline, request=request) + return form.process_request( + request, + msg_success=DEADLINE_EDITED, + redirect_url=reverse("ema:detail", args=(id,)) + "#related_data" + ) + + @login_required @conservation_office_group_required @shared_access_required(Ema, "id")