Deadline views
* replaces function based views for deadlines with class based views
This commit is contained in:
parent
a73046aa02
commit
9e6a9f4902
@ -11,7 +11,8 @@ from compensation.views.compensation.document import EditCompensationDocumentVie
|
||||
GetCompensationDocumentView, RemoveCompensationDocumentView
|
||||
from compensation.views.compensation.resubmission import CompensationResubmissionView
|
||||
from compensation.views.compensation.report import report_view
|
||||
from compensation.views.compensation.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||
from compensation.views.compensation.deadline import NewCompensationDeadlineView, EditCompensationDeadlineView, \
|
||||
RemoveCompensationDeadlineView
|
||||
from compensation.views.compensation.action import action_edit_view, action_new_view, action_remove_view
|
||||
from compensation.views.compensation.state import state_new_view, state_remove_view, state_edit_view
|
||||
from compensation.views.compensation.compensation import index_view, new_view, new_id_view, detail_view, edit_view, \
|
||||
@ -37,9 +38,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', NewCompensationDeadlineView.as_view(), name="new-deadline"),
|
||||
path('<id>/deadline/<deadline_id>/edit', EditCompensationDeadlineView.as_view(), name='deadline-edit'),
|
||||
path('<id>/deadline/<deadline_id>/remove', RemoveCompensationDeadlineView.as_view(), name='deadline-remove'),
|
||||
path('<id>/report', report_view, name='report'),
|
||||
path('<id>/resub', CompensationResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
|
@ -16,7 +16,8 @@ from compensation.views.eco_account.report import report_view
|
||||
from compensation.views.eco_account.resubmission import EcoAccountResubmissionView
|
||||
from compensation.views.eco_account.state import state_new_view, state_remove_view, state_edit_view
|
||||
from compensation.views.eco_account.action import action_edit_view, action_new_view, action_remove_view
|
||||
from compensation.views.eco_account.deadline import deadline_new_view, deadline_edit_view, deadline_remove_view
|
||||
from compensation.views.eco_account.deadline import NewEcoAccountDeadlineView, EditEcoAccountDeadlineView, \
|
||||
RemoveEcoAccountDeadlineView
|
||||
from compensation.views.eco_account.share import share_view, create_share_view
|
||||
from compensation.views.eco_account.document import GetEcoAccountDocumentView, NewEcoAccountDocumentView, \
|
||||
EditEcoAccountDocumentView, RemoveEcoAccountDocumentView
|
||||
@ -43,9 +44,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', NewEcoAccountDeadlineView.as_view(), name="new-deadline"),
|
||||
path('<id>/deadline/<deadline_id>/edit', EditEcoAccountDeadlineView.as_view(), name='deadline-edit'),
|
||||
path('<id>/deadline/<deadline_id>/remove', RemoveEcoAccountDeadlineView.as_view(), name='deadline-remove'),
|
||||
|
||||
path('<id>/share/<token>', share_view, name='share'),
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
|
@ -6,84 +6,41 @@ 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 compensation.models import Compensation
|
||||
from konova.decorators import shared_access_required, default_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 AbstractRemoveDeadlineView, AbstractEditDeadlineView, AbstractNewDeadlineView
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def deadline_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for a compensation
|
||||
class NewCompensationDeadlineView(AbstractNewDeadlineView):
|
||||
model = Compensation
|
||||
redirect_url = "compensation:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
form = NewDeadlineModalForm(request.POST or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_ADDED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
|
||||
""" Renders a form for editing deadlines from a compensation
|
||||
class EditCompensationDeadlineView(AbstractEditDeadlineView):
|
||||
model = Compensation
|
||||
redirect_url = "compensation:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
deadline_id (str): The deadline's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||
form = EditDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_EDITED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "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:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||
form = RemoveDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_REMOVED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
class RemoveCompensationDeadlineView(AbstractRemoveDeadlineView):
|
||||
model = Compensation
|
||||
redirect_url = "compensation:detail"
|
||||
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(Compensation, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
@ -6,84 +6,41 @@ 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 NewDeadlineModalForm, EditDeadlineModalForm
|
||||
from compensation.models import EcoAccount
|
||||
from konova.decorators import shared_access_required, default_group_required
|
||||
from konova.forms.modals import RemoveDeadlineModalForm
|
||||
from konova.models import Deadline
|
||||
from konova.utils.message_templates import DEADLINE_ADDED, DEADLINE_REMOVED, DEADLINE_EDITED
|
||||
from konova.views.deadline import AbstractNewDeadlineView, AbstractEditDeadlineView, AbstractRemoveDeadlineView
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def deadline_edit_view(request: HttpRequest, id: str, deadline_id: str):
|
||||
""" Renders a form for editing deadlines from a compensation
|
||||
class NewEcoAccountDeadlineView(AbstractNewDeadlineView):
|
||||
model = EcoAccount
|
||||
redirect_url = "compensation:acc:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
deadline_id (str): The deadline's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(EcoAccount, id=id)
|
||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||
form = EditDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_EDITED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str):
|
||||
""" Renders a form for removing deadlines from a compensation
|
||||
class EditEcoAccountDeadlineView(AbstractEditDeadlineView):
|
||||
model = EcoAccount
|
||||
redirect_url = "compensation:acc:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
deadline_id (str): The deadline's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(EcoAccount, id=id)
|
||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||
form = RemoveDeadlineModalForm(request.POST or None, instance=comp, deadline=deadline, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_REMOVED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def deadline_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for an eco account
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The account's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
form = NewDeadlineModalForm(request.POST or None, instance=acc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_ADDED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
class RemoveEcoAccountDeadlineView(AbstractRemoveDeadlineView):
|
||||
model = EcoAccount
|
||||
redirect_url = "compensation:acc:detail"
|
||||
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(default_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
106
konova/views/deadline.py
Normal file
106
konova/views/deadline.py
Normal file
@ -0,0 +1,106 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 22.08.22
|
||||
|
||||
"""
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.views import View
|
||||
|
||||
from compensation.forms.modals.deadline import NewDeadlineModalForm, EditDeadlineModalForm
|
||||
from konova.forms.modals import RemoveDeadlineModalForm
|
||||
from konova.models import Deadline
|
||||
from konova.utils.message_templates import DEADLINE_ADDED, DEADLINE_EDITED, DEADLINE_REMOVED
|
||||
|
||||
|
||||
class AbstractNewDeadlineView(View):
|
||||
model = None
|
||||
redirect_url = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str):
|
||||
""" Renders a form for adding new deadlines
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The account's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(self.model, id=id)
|
||||
form = NewDeadlineModalForm(request.POST or None, instance=obj, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_ADDED,
|
||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str):
|
||||
return self.get(request, id)
|
||||
|
||||
|
||||
class AbstractEditDeadlineView(View):
|
||||
model = None
|
||||
redirect_url = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str, deadline_id: str):
|
||||
""" Renders a form for editing deadlines
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
deadline_id (str): The deadline's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(self.model, id=id)
|
||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||
form = EditDeadlineModalForm(request.POST or None, instance=obj, deadline=deadline, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_EDITED,
|
||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str, deadline_id: str):
|
||||
return self.get(request, id, deadline_id)
|
||||
|
||||
|
||||
class AbstractRemoveDeadlineView(View):
|
||||
model = None
|
||||
redirect_url = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str, deadline_id: str):
|
||||
""" Renders a form for removing deadlines
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
deadline_id (str): The deadline's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(self.model, id=id)
|
||||
deadline = get_object_or_404(Deadline, id=deadline_id)
|
||||
form = RemoveDeadlineModalForm(request.POST or None, instance=obj, deadline=deadline, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=DEADLINE_REMOVED,
|
||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str, deadline_id: str):
|
||||
return self.get(request, id, deadline_id)
|
Loading…
Reference in New Issue
Block a user