#86 Edit deadlines EMA
* adds support for editing of EMA deadlines * adds buttons and urls
This commit is contained in:
parent
cba174b762
commit
3f7a6d416d
@ -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
|
||||
|
||||
|
@ -52,9 +52,12 @@
|
||||
{{ deadline.comment }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
<td class="align-middle float-right">
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'ema:deadline-remove' obj.id deadline.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove deadline' %}">
|
||||
<button data-form-url="{% url 'ema:deadline-edit' obj.id deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Edit deadline' %}">
|
||||
{% fa5_icon 'edit' %}
|
||||
</button>
|
||||
<button data-form-url="{% url 'ema:deadline-remove' obj.id deadline.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove deadline' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
@ -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,
|
||||
|
@ -28,8 +28,10 @@ urlpatterns = [
|
||||
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||
path('<id>/action/<action_id>/remove', action_remove_view, name='action-remove'),
|
||||
|
||||
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||
path('<id>/deadline/new', deadline_new_view, name="new-deadline"),
|
||||
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
||||
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
||||
|
||||
path('<id>/share/<token>', share_view, name='share'),
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
|
||||
|
28
ema/views.py
28
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")
|
||||
|
Loading…
Reference in New Issue
Block a user