mpeltriaux
122c9cb363
* refactors BaseForm request/user initialization * introduces mark_as_edited() method for compensation models
59 lines
1.7 KiB
Python
59 lines
1.7 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.auth.decorators import login_required
|
|
from django.http import HttpRequest
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from compensation.forms.modalForms import NewPaymentForm
|
|
from compensation.models import Payment
|
|
from intervention.models import Intervention
|
|
from konova.decorators import default_group_required
|
|
from konova.forms import RemoveModalForm
|
|
|
|
|
|
@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, request=request)
|
|
return form.process_request(
|
|
request,
|
|
msg_success=_("Payment added")
|
|
)
|
|
|
|
|
|
@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, request=request)
|
|
return form.process_request(
|
|
request=request,
|
|
msg_success=_("Payment removed"),
|
|
)
|
|
|