104_Class_based_views #200
@ -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('<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/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>/deadline/new', NewEmaDeadlineView.as_view(), name="new-deadline"),
|
||||
path('<id>/deadline/<deadline_id>/edit', EditEmaDeadlineView.as_view(), name='deadline-edit'),
|
||||
path('<id>/deadline/<deadline_id>/remove', RemoveEmaDeadlineView.as_view(), name='deadline-remove'),
|
||||
|
||||
path('<id>/share/<token>', share_view, name='share'),
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user