mpeltriaux
9654f6873d
* splits compensation/views/eco_account.py (+700 lines) into separate files in new module * view files can now be found in /compensation/views/eco_account/...
90 lines
3.0 KiB
Python
90 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.compensation_action import EditCompensationActionModalForm, \
|
|
RemoveCompensationActionModalForm, NewCompensationActionModalForm
|
|
from compensation.models import EcoAccount, CompensationAction
|
|
from konova.decorators import shared_access_required, default_group_required
|
|
from konova.utils.message_templates import COMPENSATION_ACTION_EDITED, COMPENSATION_ACTION_REMOVED, \
|
|
COMPENSATION_ACTION_ADDED
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
@shared_access_required(EcoAccount, "id")
|
|
def action_new_view(request: HttpRequest, id: str):
|
|
""" Renders a form for adding new actions 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 = NewCompensationActionModalForm(request.POST or None, instance=acc, request=request)
|
|
return form.process_request(
|
|
request,
|
|
msg_success=COMPENSATION_ACTION_ADDED,
|
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
|
)
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
@shared_access_required(EcoAccount, "id")
|
|
def action_remove_view(request: HttpRequest, id: str, action_id: str):
|
|
""" Renders a form for removing a compensation action
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
id (str): The compensation's id
|
|
id (str): The action's id
|
|
|
|
Returns:
|
|
|
|
"""
|
|
acc = get_object_or_404(EcoAccount, id=id)
|
|
action = get_object_or_404(CompensationAction, id=action_id)
|
|
form = RemoveCompensationActionModalForm(request.POST or None, instance=acc, action=action, request=request)
|
|
return form.process_request(
|
|
request,
|
|
msg_success=COMPENSATION_ACTION_REMOVED,
|
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
|
)
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
@shared_access_required(EcoAccount, "id")
|
|
def action_edit_view(request: HttpRequest, id: str, action_id: str):
|
|
""" Renders a form for editing a compensation action
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
id (str): The compensation's id
|
|
id (str): The action's id
|
|
|
|
Returns:
|
|
|
|
"""
|
|
acc = get_object_or_404(EcoAccount, id=id)
|
|
action = get_object_or_404(CompensationAction, id=action_id)
|
|
form = EditCompensationActionModalForm(request.POST or None, instance=acc, action=action, request=request)
|
|
return form.process_request(
|
|
request,
|
|
msg_success=COMPENSATION_ACTION_EDITED,
|
|
redirect_url=reverse("compensation:acc:detail", args=(id,)) + "#related_data"
|
|
)
|
|
|