State views
* replaces function based state views with class based
This commit is contained in:
parent
d6057575ea
commit
1b5cbba48b
@ -14,7 +14,8 @@ from compensation.views.compensation.report import report_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.state import NewCompensationStateView, EditCompensationStateView, \
|
||||
RemoveCompensationStateView
|
||||
from compensation.views.compensation.compensation import index_view, new_view, new_id_view, detail_view, edit_view, \
|
||||
remove_view
|
||||
from compensation.views.compensation.log import CompensationLogView
|
||||
@ -30,9 +31,9 @@ urlpatterns = [
|
||||
path('<id>/edit', edit_view, name='edit'),
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
|
||||
path('<id>/state/new', state_new_view, name='new-state'),
|
||||
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||
path('<id>/state/new', NewCompensationStateView.as_view(), name='new-state'),
|
||||
path('<id>/state/<state_id>/edit', EditCompensationStateView.as_view(), name='state-edit'),
|
||||
path('<id>/state/<state_id>/remove', RemoveCompensationStateView.as_view(), name='state-remove'),
|
||||
|
||||
path('<id>/action/new', action_new_view, name='new-action'),
|
||||
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||
|
@ -14,7 +14,8 @@ from compensation.views.eco_account.log import EcoAccountLogView
|
||||
from compensation.views.eco_account.record import EcoAccountRecordView
|
||||
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.state import NewEcoAccountStateView, EditEcoAccountStateView, \
|
||||
RemoveEcoAccountStateView
|
||||
from compensation.views.eco_account.action import action_edit_view, action_new_view, action_remove_view
|
||||
from compensation.views.eco_account.deadline import NewEcoAccountDeadlineView, EditEcoAccountDeadlineView, \
|
||||
RemoveEcoAccountDeadlineView
|
||||
@ -36,9 +37,9 @@ urlpatterns = [
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
path('<id>/resub', EcoAccountResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
path('<id>/state/new', state_new_view, name='new-state'),
|
||||
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||
path('<id>/state/new', NewEcoAccountStateView.as_view(), name='new-state'),
|
||||
path('<id>/state/<state_id>/edit', EditEcoAccountStateView.as_view(), name='state-edit'),
|
||||
path('<id>/state/<state_id>/remove', RemoveEcoAccountStateView.as_view(), name='state-remove'),
|
||||
|
||||
path('<id>/action/new', action_new_view, name='new-action'),
|
||||
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||
|
@ -6,84 +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.state import EditCompensationStateModalForm, RemoveCompensationStateModalForm, \
|
||||
NewCompensationStateModalForm
|
||||
from compensation.models import Compensation, CompensationState
|
||||
from compensation.models import Compensation
|
||||
from konova.decorators import shared_access_required, default_group_required
|
||||
from konova.utils.message_templates import COMPENSATION_STATE_EDITED, COMPENSATION_STATE_REMOVED, \
|
||||
COMPENSATION_STATE_ADDED
|
||||
from konova.views.state import AbstractNewCompensationStateView, AbstractEditCompensationStateView, \
|
||||
AbstractRemoveCompensationStateView
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def state_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for a compensation
|
||||
class NewCompensationStateView(AbstractNewCompensationStateView):
|
||||
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 = NewCompensationStateModalForm(request.POST or None, instance=comp, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_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 state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for removing a compensation state
|
||||
class EditCompensationStateView(AbstractEditCompensationStateView):
|
||||
model = Compensation
|
||||
redirect_url = "compensation:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = RemoveCompensationStateModalForm(request.POST or None, instance=comp, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_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)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Compensation, "id")
|
||||
def state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for editing a compensation state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = EditCompensationStateModalForm(request.POST or None, instance=comp, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_EDITED,
|
||||
redirect_url=reverse("compensation:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
class RemoveCompensationStateView(AbstractRemoveCompensationStateView):
|
||||
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,83 +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.state import EditCompensationStateModalForm, RemoveCompensationStateModalForm, \
|
||||
NewCompensationStateModalForm
|
||||
from compensation.models import EcoAccount, CompensationState
|
||||
from compensation.models import EcoAccount
|
||||
from konova.decorators import shared_access_required, default_group_required
|
||||
from konova.utils.message_templates import COMPENSATION_STATE_EDITED, COMPENSATION_STATE_REMOVED, \
|
||||
COMPENSATION_STATE_ADDED
|
||||
from konova.views.state import AbstractNewCompensationStateView, AbstractEditCompensationStateView, \
|
||||
AbstractRemoveCompensationStateView
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def state_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for an eco account
|
||||
class NewEcoAccountStateView(AbstractNewCompensationStateView):
|
||||
model = EcoAccount
|
||||
redirect_url = "compensation:acc:detail"
|
||||
|
||||
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 = NewCompensationStateModalForm(request.POST or None, instance=acc, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_ADDED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for removing a compensation state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = RemoveCompensationStateModalForm(request.POST or None, instance=acc, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_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 state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for editing a compensation state
|
||||
class EditEcoAccountStateView(AbstractEditCompensationStateView):
|
||||
model = EcoAccount
|
||||
redirect_url = "compensation:acc:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
state_id (str): The state's id
|
||||
@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)
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = EditCompensationStateModalForm(request.POST or None, instance=acc, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_EDITED,
|
||||
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
class RemoveEcoAccountStateView(AbstractRemoveCompensationStateView):
|
||||
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)
|
||||
|
@ -16,7 +16,7 @@ from ema.views.record import EmaRecordView
|
||||
from ema.views.report import report_view
|
||||
from ema.views.resubmission import EmaResubmissionView
|
||||
from ema.views.share import share_view, create_share_view
|
||||
from ema.views.state import state_new_view, state_remove_view, state_edit_view
|
||||
from ema.views.state import NewEmaStateView, EditEmaStateView, RemoveEmaStateView
|
||||
|
||||
app_name = "ema"
|
||||
urlpatterns = [
|
||||
@ -31,9 +31,9 @@ urlpatterns = [
|
||||
path('<id>/report', report_view, name='report'),
|
||||
path('<id>/resub', EmaResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
path('<id>/state/new', state_new_view, name='new-state'),
|
||||
path('<id>/state/<state_id>/remove', state_remove_view, name='state-remove'),
|
||||
path('<id>/state/<state_id>/edit', state_edit_view, name='state-edit'),
|
||||
path('<id>/state/new', NewEmaStateView.as_view(), name='new-state'),
|
||||
path('<id>/state/<state_id>/remove', RemoveEmaStateView.as_view(), name='state-remove'),
|
||||
path('<id>/state/<state_id>/edit', EditEmaStateView.as_view(), name='state-edit'),
|
||||
|
||||
path('<id>/action/new', action_new_view, name='new-action'),
|
||||
path('<id>/action/<action_id>/edit', action_edit_view, name='action-edit'),
|
||||
|
@ -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.state import NewCompensationStateModalForm, RemoveCompensationStateModalForm, \
|
||||
EditCompensationStateModalForm
|
||||
from compensation.models import CompensationState
|
||||
from ema.models import Ema
|
||||
from konova.decorators import conservation_office_group_required, shared_access_required
|
||||
from konova.utils.message_templates import COMPENSATION_STATE_ADDED, COMPENSATION_STATE_REMOVED, \
|
||||
COMPENSATION_STATE_EDITED
|
||||
from konova.views.state import AbstractNewCompensationStateView, AbstractEditCompensationStateView, \
|
||||
AbstractRemoveCompensationStateView
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Ema, "id")
|
||||
def state_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for an EMA
|
||||
class NewEmaStateView(AbstractNewCompensationStateView):
|
||||
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 = NewCompensationStateModalForm(request.POST or None, instance=ema, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_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 state_remove_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for removing an EMA state
|
||||
class EditEmaStateView(AbstractEditCompensationStateView):
|
||||
model = Ema
|
||||
redirect_url = "ema:detail"
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The ema id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = RemoveCompensationStateModalForm(request.POST or None, instance=ema, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_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)
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Ema, "id")
|
||||
def state_edit_view(request: HttpRequest, id: str, state_id: str):
|
||||
""" Renders a form for editing an EMA state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The ema id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = EditCompensationStateModalForm(request.POST or None, instance=ema, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_EDITED,
|
||||
redirect_url=reverse("ema:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
class RemoveEmaStateView(AbstractRemoveCompensationStateView):
|
||||
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)
|
||||
|
107
konova/views/state.py
Normal file
107
konova/views/state.py
Normal file
@ -0,0 +1,107 @@
|
||||
"""
|
||||
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.state import NewCompensationStateModalForm, EditCompensationStateModalForm, \
|
||||
RemoveCompensationStateModalForm
|
||||
from compensation.models import CompensationState
|
||||
from konova.utils.message_templates import COMPENSATION_STATE_ADDED, COMPENSATION_STATE_EDITED, \
|
||||
COMPENSATION_STATE_REMOVED
|
||||
|
||||
|
||||
class AbstractCompensationStateView(View):
|
||||
model = None
|
||||
redirect_url = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class AbstractNewCompensationStateView(AbstractCompensationStateView):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str):
|
||||
""" Renders a form for adding new states
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The object's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(self.model, id=id)
|
||||
form = NewCompensationStateModalForm(request.POST or None, instance=obj, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_ADDED,
|
||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str):
|
||||
return self.get(request, id)
|
||||
|
||||
|
||||
class AbstractEditCompensationStateView(AbstractCompensationStateView):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str, state_id: str):
|
||||
""" Renders a form for editing a state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The object id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(self.model, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = EditCompensationStateModalForm(request.POST or None, instance=obj, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_EDITED,
|
||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str, state_id: str):
|
||||
return self.get(request, id, state_id)
|
||||
|
||||
|
||||
class AbstractRemoveCompensationStateView(AbstractCompensationStateView):
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
def get(self, request, id: str, state_id: str):
|
||||
""" Renders a form for removing astate
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The object id
|
||||
state_id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = get_object_or_404(self.model, id=id)
|
||||
state = get_object_or_404(CompensationState, id=state_id)
|
||||
form = RemoveCompensationStateModalForm(request.POST or None, instance=obj, state=state, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=COMPENSATION_STATE_REMOVED,
|
||||
redirect_url=reverse(self.redirect_url, args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
def post(self, request, id: str, state_id: str):
|
||||
return self.get(request, id, state_id)
|
||||
|
Loading…
Reference in New Issue
Block a user