a7aeecde2e
* reduce compensation/views.py file size by splitting into three sub view files in compensation/views/xy_views.py for compensation, eco-account and payment * restructure urlpattern list by splitting into three smaller lists for a better overview and maintainability
81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
"""
|
|
Author: Michel Peltriaux
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
Created on: 09.08.21
|
|
|
|
"""
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.contrib import messages
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.http import HttpRequest
|
|
from django.shortcuts import get_object_or_404, render, redirect
|
|
|
|
from compensation.forms import NewPaymentForm
|
|
from compensation.models import Payment
|
|
from intervention.models import Intervention
|
|
from konova.contexts import BaseContext
|
|
from konova.decorators import default_group_required
|
|
from konova.forms import RemoveModalForm
|
|
from konova.utils.message_templates import FORM_INVALID
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
def new_payment_view(request: HttpRequest, intervention_id: str):
|
|
""" Renders a modal view for adding new payments
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
intervention_id (str): The intervention's id for which a new payment shall be added
|
|
|
|
Returns:
|
|
|
|
"""
|
|
intervention = get_object_or_404(Intervention, id=intervention_id)
|
|
form = NewPaymentForm(request.POST or None, instance=intervention, user=request.user)
|
|
template = form.template
|
|
if request.method == "POST":
|
|
if form.is_valid():
|
|
payment = form.save()
|
|
messages.success(
|
|
request,
|
|
_("Payment added")
|
|
)
|
|
return redirect(request.META.get("HTTP_REFERER", "home"))
|
|
else:
|
|
messages.info(
|
|
request,
|
|
FORM_INVALID
|
|
)
|
|
return redirect(request.META.get("HTTP_REFERER", "home"))
|
|
elif request.method == "GET":
|
|
context = {
|
|
"form": form,
|
|
}
|
|
context = BaseContext(request, context).context
|
|
return render(request, template, context)
|
|
else:
|
|
raise NotImplementedError
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
def payment_remove_view(request: HttpRequest, id: str):
|
|
""" Renders a modal view for removing payments
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
id (str): The payment's id
|
|
|
|
Returns:
|
|
|
|
"""
|
|
payment = get_object_or_404(Payment, id=id)
|
|
form = RemoveModalForm(request.POST or None, instance=payment, user=request.user)
|
|
return form.process_request(
|
|
request=request,
|
|
msg_success=_("Payment removed"),
|
|
)
|
|
|