diff --git a/ema/urls.py b/ema/urls.py index 770e24c8..eda06728 100644 --- a/ema/urls.py +++ b/ema/urls.py @@ -8,7 +8,7 @@ Created on: 19.08.21 from django.urls import path from ema.views.action import action_new_view, action_edit_view, action_remove_view -from ema.views.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view +from ema.views.deadline import NewEmaDeadlineView, EditEmaDeadlineView, RemoveEmaDeadlineView from ema.views.document import NewEmaDocumentView, EditEmaDocumentView, RemoveEmaDocumentView, GetEmaDocumentView from ema.views.ema import index_view, new_view, new_id_view, detail_view, edit_view, remove_view from ema.views.log import EmaLogView @@ -39,9 +39,9 @@ urlpatterns = [ path('/action//edit', action_edit_view, name='action-edit'), 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('/deadline/new', NewEmaDeadlineView.as_view(), name="new-deadline"), + path('/deadline//edit', EditEmaDeadlineView.as_view(), name='deadline-edit'), + path('/deadline//remove', RemoveEmaDeadlineView.as_view(), name='deadline-remove'), path('/share/', share_view, name='share'), path('/share', create_share_view, name='share-create'), diff --git a/ema/views/deadline.py b/ema/views/deadline.py index 223ceeb0..76c2bded 100644 --- a/ema/views/deadline.py +++ b/ema/views/deadline.py @@ -6,85 +6,42 @@ Created on: 19.08.22 """ from django.contrib.auth.decorators import login_required -from django.http import HttpRequest -from django.shortcuts import get_object_or_404 -from django.urls import reverse +from django.utils.decorators import method_decorator -from compensation.forms.modals.deadline import EditDeadlineModalForm, NewDeadlineModalForm from ema.models import Ema from konova.decorators import shared_access_required, conservation_office_group_required -from konova.forms.modals import RemoveDeadlineModalForm -from konova.models import Deadline -from konova.utils.message_templates import DEADLINE_REMOVED, DEADLINE_EDITED, DEADLINE_ADDED +from konova.views.deadline import AbstractNewDeadlineView, AbstractRemoveDeadlineView, AbstractEditDeadlineView -@login_required -@conservation_office_group_required -@shared_access_required(Ema, "id") -def deadline_new_view(request: HttpRequest, id: str): - """ Renders a form for adding new states for an EMA +class NewEmaDeadlineView(AbstractNewDeadlineView): + model = Ema + redirect_url = "ema:detail" - Args: - request (HttpRequest): The incoming request - id (str): The EMA's id to which the new state will be related - - Returns: - - """ - ema = get_object_or_404(Ema, id=id) - form = NewDeadlineModalForm(request.POST or None, instance=ema, request=request) - return form.process_request( - request, - msg_success=DEADLINE_ADDED, - redirect_url=reverse("ema:detail", args=(id,)) + "#related_data" - ) + @method_decorator(login_required) + @method_decorator(conservation_office_group_required) + @method_decorator(shared_access_required(Ema, "id")) + def dispatch(self, request, *args, **kwargs): + return super().dispatch(request, *args, **kwargs) -@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 +class EditEmaDeadlineView(AbstractEditDeadlineView): + model = Ema + redirect_url = "ema:detail" - 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" - ) + @method_decorator(login_required) + @method_decorator(conservation_office_group_required) + @method_decorator(shared_access_required(Ema, "id")) + def dispatch(self, request, *args, **kwargs): + return super().dispatch(request, *args, **kwargs) -@login_required -@conservation_office_group_required -@shared_access_required(Ema, "id") -def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str): - """ Renders a form for removing 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 = RemoveDeadlineModalForm(request.POST or None, instance=ema, deadline=deadline, request=request) - return form.process_request( - request, - msg_success=DEADLINE_REMOVED, - redirect_url=reverse("ema:detail", args=(id,)) + "#related_data" - ) +class RemoveEmaDeadlineView(AbstractRemoveDeadlineView): + model = Ema + redirect_url = "ema:detail" + @method_decorator(login_required) + @method_decorator(conservation_office_group_required) + @method_decorator(shared_access_required(Ema, "id")) + def dispatch(self, request, *args, **kwargs): + return super().dispatch(request, *args, **kwargs)