# Revocation Intervention views
* refactors revocation method views for intervention into classes
This commit is contained in:
parent
e70a8b51d1
commit
3966521cd4
@ -22,8 +22,8 @@ from intervention.views.log import InterventionLogView
|
||||
from intervention.views.record import InterventionRecordView
|
||||
from intervention.views.report import InterventionPublicReportView
|
||||
from intervention.views.resubmission import InterventionResubmissionView
|
||||
from intervention.views.revocation import new_revocation_view, edit_revocation_view, remove_revocation_view, \
|
||||
get_revocation_view
|
||||
from intervention.views.revocation import NewInterventionRevocationView, GetInterventionRevocationView, \
|
||||
EditInterventionRevocationView, RemoveInterventionRevocationView
|
||||
from intervention.views.share import InterventionShareFormView, InterventionShareByTokenView
|
||||
|
||||
app_name = "intervention"
|
||||
@ -57,10 +57,10 @@ urlpatterns = [
|
||||
path('<id>/deduction/<deduction_id>/remove', RemoveInterventionDeductionView.as_view(), name='remove-deduction'),
|
||||
|
||||
# Revocation routes
|
||||
path('<id>/revocation/new', new_revocation_view, name='new-revocation'),
|
||||
path('<id>/revocation/<revocation_id>/edit', edit_revocation_view, name='edit-revocation'),
|
||||
path('<id>/revocation/<revocation_id>/remove', remove_revocation_view, name='remove-revocation'),
|
||||
path('revocation/<doc_id>', get_revocation_view, name='get-doc-revocation'),
|
||||
path('<id>/revocation/new', NewInterventionRevocationView.as_view(), name='new-revocation'),
|
||||
path('<id>/revocation/<revocation_id>/edit', EditInterventionRevocationView.as_view(), name='edit-revocation'),
|
||||
path('<id>/revocation/<revocation_id>/remove', RemoveInterventionRevocationView.as_view(), name='remove-revocation'),
|
||||
path('revocation/<doc_id>', GetInterventionRevocationView.as_view(), name='get-doc-revocation'),
|
||||
|
||||
# Autocomplete
|
||||
path("atcmplt/interventions", InterventionAutocomplete.as_view(), name="autocomplete"),
|
||||
|
||||
@ -6,10 +6,12 @@ Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
||||
from intervention.forms.modals.revocation import NewRevocationModalForm, EditRevocationModalForm, \
|
||||
RemoveRevocationModalForm
|
||||
@ -19,100 +21,125 @@ from konova.utils.documents import get_document
|
||||
from konova.utils.message_templates import REVOCATION_ADDED, DATA_UNSHARED, REVOCATION_EDITED, REVOCATION_REMOVED
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def new_revocation_view(request: HttpRequest, id: str):
|
||||
""" Renders sharing form for an intervention
|
||||
class NewInterventionRevocationView(LoginRequiredMixin, View):
|
||||
def __process_request(self, request: HttpRequest, id: str, *args, **kwargs) -> HttpResponse:
|
||||
""" Renders sharing form for an intervention
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): Intervention's id
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): Intervention's id
|
||||
|
||||
Returns:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = NewRevocationModalForm(request.POST or None, request.FILES or None, instance=intervention, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=REVOCATION_ADDED,
|
||||
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def get_revocation_view(request: HttpRequest, doc_id: str):
|
||||
""" Returns the revocation document as downloadable file
|
||||
|
||||
Wraps the generic document fetcher function from konova.utils.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
doc_id (str): The document id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
doc = get_object_or_404(RevocationDocument, id=doc_id)
|
||||
# File download only possible if related instance is shared with user
|
||||
if not doc.instance.legal.intervention.users.filter(id=request.user.id):
|
||||
messages.info(
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
form = NewRevocationModalForm(request.POST or None, request.FILES or None, instance=intervention,
|
||||
request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
DATA_UNSHARED
|
||||
msg_success=REVOCATION_ADDED,
|
||||
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
return redirect("intervention:detail", id=doc.instance.id)
|
||||
return get_document(doc)
|
||||
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def get(self, request: HttpRequest, id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, *args, **kwargs)
|
||||
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def post(self, request: HttpRequest, id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def edit_revocation_view(request: HttpRequest, id: str, revocation_id: str):
|
||||
""" Renders a edit view for a revocation
|
||||
class GetInterventionRevocationView(LoginRequiredMixin, View):
|
||||
@method_decorator(default_group_required)
|
||||
def get(self, request: HttpRequest, doc_id: str, *args, **kwargs) -> HttpResponse:
|
||||
""" Returns the revocation document as downloadable file
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id as string
|
||||
revocation_id (str): The revocation's id as string
|
||||
Wraps the generic document fetcher function from konova.utils.
|
||||
|
||||
Returns:
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
doc_id (str): The document id
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
revocation = get_object_or_404(Revocation, id=revocation_id)
|
||||
Returns:
|
||||
|
||||
form = EditRevocationModalForm(request.POST or None, request.FILES or None, instance=intervention, revocation=revocation, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
REVOCATION_EDITED,
|
||||
redirect_url=reverse("intervention:detail", args=(intervention.id,)) + "#related_data"
|
||||
)
|
||||
"""
|
||||
doc = get_object_or_404(RevocationDocument, id=doc_id)
|
||||
# File download only possible if related instance is shared with user
|
||||
if not doc.instance.legal.intervention.users.filter(id=request.user.id):
|
||||
messages.info(
|
||||
request,
|
||||
DATA_UNSHARED
|
||||
)
|
||||
return redirect("intervention:detail", id=doc.instance.id)
|
||||
return get_document(doc)
|
||||
|
||||
|
||||
@login_required_modal
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def remove_revocation_view(request: HttpRequest, id: str, revocation_id: str):
|
||||
""" Renders a remove view for a revocation
|
||||
class EditInterventionRevocationView(LoginRequiredMixin, View):
|
||||
def __process_request(self, request: HttpRequest, id: str, revocation_id: str, *args, **kwargs) -> HttpResponse:
|
||||
""" Renders a edit view for a revocation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id as string
|
||||
revocation_id (str): The revocation's id as string
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id as string
|
||||
revocation_id (str): The revocation's id as string
|
||||
|
||||
Returns:
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
revocation = get_object_or_404(Revocation, id=revocation_id)
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
revocation = get_object_or_404(Revocation, id=revocation_id)
|
||||
|
||||
form = RemoveRevocationModalForm(request.POST or None, instance=intervention, revocation=revocation, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
REVOCATION_REMOVED,
|
||||
redirect_url=reverse("intervention:detail", args=(intervention.id,)) + "#related_data"
|
||||
)
|
||||
form = EditRevocationModalForm(request.POST or None, request.FILES or None, instance=intervention,
|
||||
revocation=revocation, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
REVOCATION_EDITED,
|
||||
redirect_url=reverse("intervention:detail", args=(intervention.id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def get(self, request: HttpRequest, id: str, revocation_id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, revocation_id, *args, **kwargs)
|
||||
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def post(self, request: HttpRequest, id: str, revocation_id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, revocation_id, *args, **kwargs)
|
||||
|
||||
|
||||
class RemoveInterventionRevocationView(LoginRequiredMixin, View):
|
||||
def __process_request(self, request, id: str, revocation_id: str, *args, **kwargs) -> HttpResponse:
|
||||
""" Renders a remove view for a revocation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id as string
|
||||
revocation_id (str): The revocation's id as string
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
revocation = get_object_or_404(Revocation, id=revocation_id)
|
||||
|
||||
form = RemoveRevocationModalForm(request.POST or None, instance=intervention, revocation=revocation,
|
||||
request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
REVOCATION_REMOVED,
|
||||
redirect_url=reverse("intervention:detail", args=(intervention.id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def get(self, request: HttpRequest, id: str, revocation_id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, revocation_id, *args, **kwargs)
|
||||
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Intervention, "id"))
|
||||
def post(self, request, id: str, revocation_id: str, *args, **kwargs) -> HttpResponse:
|
||||
return self.__process_request(request, id, revocation_id, *args, **kwargs)
|
||||
Loading…
x
Reference in New Issue
Block a user