104_Class_based_views #200

Merged
mpeltriaux merged 21 commits from 104_Class_based_views into master 2022-08-22 11:09:51 +02:00
2 changed files with 30 additions and 73 deletions
Showing only changes of commit 59b77fe567 - Show all commits

View File

@ -8,7 +8,7 @@ Created on: 19.08.21
from django.urls import path from django.urls import path
from ema.views.action import action_new_view, action_edit_view, action_remove_view 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.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.ema import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
from ema.views.log import EmaLogView from ema.views.log import EmaLogView
@ -39,9 +39,9 @@ urlpatterns = [
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'), 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>/action/<action_id>/remove', action_remove_view, name='action-remove'),
path('<id>/deadline/new', deadline_new_view, name="new-deadline"), path('<id>/deadline/new', NewEmaDeadlineView.as_view(), name="new-deadline"),
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'), path('<id>/deadline/<deadline_id>/edit', EditEmaDeadlineView.as_view(), name='deadline-edit'),
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'), path('<id>/deadline/<deadline_id>/remove', RemoveEmaDeadlineView.as_view(), name='deadline-remove'),
path('<id>/share/<token>', share_view, name='share'), path('<id>/share/<token>', share_view, name='share'),
path('<id>/share', create_share_view, name='share-create'), path('<id>/share', create_share_view, name='share-create'),

View File

@ -6,85 +6,42 @@ Created on: 19.08.22
""" """
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.http import HttpRequest from django.utils.decorators import method_decorator
from django.shortcuts import get_object_or_404
from django.urls import reverse
from compensation.forms.modals.deadline import EditDeadlineModalForm, NewDeadlineModalForm
from ema.models import Ema from ema.models import Ema
from konova.decorators import shared_access_required, conservation_office_group_required from konova.decorators import shared_access_required, conservation_office_group_required
from konova.forms.modals import RemoveDeadlineModalForm from konova.views.deadline import AbstractNewDeadlineView, AbstractRemoveDeadlineView, AbstractEditDeadlineView
from konova.models import Deadline
from konova.utils.message_templates import DEADLINE_REMOVED, DEADLINE_EDITED, DEADLINE_ADDED
@login_required class NewEmaDeadlineView(AbstractNewDeadlineView):
@conservation_office_group_required model = Ema
@shared_access_required(Ema, "id") redirect_url = "ema:detail"
def deadline_new_view(request: HttpRequest, id: str):
""" Renders a form for adding new states for an EMA
Args: @method_decorator(login_required)
request (HttpRequest): The incoming request @method_decorator(conservation_office_group_required)
id (str): The EMA's id to which the new state will be related @method_decorator(shared_access_required(Ema, "id"))
def dispatch(self, request, *args, **kwargs):
Returns: return super().dispatch(request, *args, **kwargs)
"""
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"
)
@login_required class EditEmaDeadlineView(AbstractEditDeadlineView):
@conservation_office_group_required model = Ema
@shared_access_required(Ema, "id") redirect_url = "ema:detail"
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
""" Renders a form for editing deadlines from a compensation
Args: @method_decorator(login_required)
request (HttpRequest): The incoming request @method_decorator(conservation_office_group_required)
id (str): The compensation's id @method_decorator(shared_access_required(Ema, "id"))
deadline_id (str): The deadline's id def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)
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 class RemoveEmaDeadlineView(AbstractRemoveDeadlineView):
@conservation_office_group_required model = Ema
@shared_access_required(Ema, "id") redirect_url = "ema:detail"
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"
)
@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)