89 lines
3.0 KiB
Python
89 lines
3.0 KiB
Python
|
"""
|
||
|
Author: Michel Peltriaux
|
||
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
||
|
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 compensation.forms.modals.state import EditCompensationStateModalForm, RemoveCompensationStateModalForm, \
|
||
|
NewCompensationStateModalForm
|
||
|
from compensation.models import EcoAccount, CompensationState
|
||
|
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
|
||
|
|
||
|
|
||
|
@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
|
||
|
|
||
|
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"
|
||
|
)
|
||
|
|
||
|
|
||
|
@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
|
||
|
|
||
|
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 = 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"
|
||
|
)
|
||
|
|