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
|
GetCompensationDocumentView, RemoveCompensationDocumentView
|
||||||
from compensation.views.compensation.resubmission import CompensationResubmissionView
|
from compensation.views.compensation.resubmission import CompensationResubmissionView
|
||||||
from compensation.views.compensation.report import report_view
|
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.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.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, \
|
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>/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', NewCompensationDeadlineView.as_view(), name="new-deadline"),
|
||||||
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
path('<id>/deadline/<deadline_id>/edit', EditCompensationDeadlineView.as_view(), name='deadline-edit'),
|
||||||
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
path('<id>/deadline/<deadline_id>/remove', RemoveCompensationDeadlineView.as_view(), name='deadline-remove'),
|
||||||
path('<id>/report', report_view, name='report'),
|
path('<id>/report', report_view, name='report'),
|
||||||
path('<id>/resub', CompensationResubmissionView.as_view(), name='resubmission-create'),
|
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.resubmission import EcoAccountResubmissionView
|
||||||
from compensation.views.eco_account.state import state_new_view, state_remove_view, state_edit_view
|
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.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.share import share_view, create_share_view
|
||||||
from compensation.views.eco_account.document import GetEcoAccountDocumentView, NewEcoAccountDocumentView, \
|
from compensation.views.eco_account.document import GetEcoAccountDocumentView, NewEcoAccountDocumentView, \
|
||||||
EditEcoAccountDocumentView, RemoveEcoAccountDocumentView
|
EditEcoAccountDocumentView, RemoveEcoAccountDocumentView
|
||||||
@ -43,9 +44,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', NewEcoAccountDeadlineView.as_view(), name="new-deadline"),
|
||||||
path('<id>/deadline/<deadline_id>/edit', deadline_edit_view, name='deadline-edit'),
|
path('<id>/deadline/<deadline_id>/edit', EditEcoAccountDeadlineView.as_view(), name='deadline-edit'),
|
||||||
path('<id>/deadline/<deadline_id>/remove', deadline_remove_view, name='deadline-remove'),
|
path('<id>/deadline/<deadline_id>/remove', RemoveEcoAccountDeadlineView.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'),
|
||||||
|
@ -6,84 +6,41 @@ 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 compensation.models import Compensation
|
from compensation.models import Compensation
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.forms.modals import RemoveDeadlineModalForm
|
from konova.views.deadline import AbstractRemoveDeadlineView, AbstractEditDeadlineView, AbstractNewDeadlineView
|
||||||
from konova.models import Deadline
|
|
||||||
from konova.utils.message_templates import DEADLINE_REMOVED, DEADLINE_EDITED, DEADLINE_ADDED
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class NewCompensationDeadlineView(AbstractNewDeadlineView):
|
||||||
@default_group_required
|
model = Compensation
|
||||||
@shared_access_required(Compensation, "id")
|
redirect_url = "compensation:detail"
|
||||||
def deadline_new_view(request: HttpRequest, id: str):
|
|
||||||
""" Renders a form for adding new states for a compensation
|
|
||||||
|
|
||||||
Args:
|
@method_decorator(login_required)
|
||||||
request (HttpRequest): The incoming request
|
@method_decorator(default_group_required)
|
||||||
id (str): The compensation's id to which the new state will be related
|
@method_decorator(shared_access_required(Compensation, "id"))
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
Returns:
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
"""
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class EditCompensationDeadlineView(AbstractEditDeadlineView):
|
||||||
@default_group_required
|
model = Compensation
|
||||||
@shared_access_required(Compensation, "id")
|
redirect_url = "compensation: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(default_group_required)
|
||||||
id (str): The compensation's id
|
@method_decorator(shared_access_required(Compensation, "id"))
|
||||||
deadline_id (str): The deadline's id
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class RemoveCompensationDeadlineView(AbstractRemoveDeadlineView):
|
||||||
@default_group_required
|
model = Compensation
|
||||||
@shared_access_required(Compensation, "id")
|
redirect_url = "compensation: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:
|
|
||||||
|
|
||||||
"""
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@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.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 NewDeadlineModalForm, EditDeadlineModalForm
|
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
from konova.decorators import shared_access_required, default_group_required
|
from konova.decorators import shared_access_required, default_group_required
|
||||||
from konova.forms.modals import RemoveDeadlineModalForm
|
from konova.views.deadline import AbstractNewDeadlineView, AbstractEditDeadlineView, AbstractRemoveDeadlineView
|
||||||
from konova.models import Deadline
|
|
||||||
from konova.utils.message_templates import DEADLINE_ADDED, DEADLINE_REMOVED, DEADLINE_EDITED
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class NewEcoAccountDeadlineView(AbstractNewDeadlineView):
|
||||||
@default_group_required
|
model = EcoAccount
|
||||||
@shared_access_required(EcoAccount, "id")
|
redirect_url = "compensation:acc: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(default_group_required)
|
||||||
id (str): The compensation's id
|
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||||
deadline_id (str): The deadline's id
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class EditEcoAccountDeadlineView(AbstractEditDeadlineView):
|
||||||
@default_group_required
|
model = EcoAccount
|
||||||
@shared_access_required(EcoAccount, "id")
|
redirect_url = "compensation:acc:detail"
|
||||||
def deadline_remove_view(request: HttpRequest, id: str, deadline_id: str):
|
|
||||||
""" Renders a form for removing deadlines from a compensation
|
|
||||||
|
|
||||||
Args:
|
@method_decorator(login_required)
|
||||||
request (HttpRequest): The incoming request
|
@method_decorator(default_group_required)
|
||||||
id (str): The compensation's id
|
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||||
deadline_id (str): The deadline's id
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class RemoveEcoAccountDeadlineView(AbstractRemoveDeadlineView):
|
||||||
@default_group_required
|
model = EcoAccount
|
||||||
@shared_access_required(EcoAccount, "id")
|
redirect_url = "compensation:acc:detail"
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
@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