Payments add modal form
* adds modal form for adding payments * generalizes generic_table_form.html for table-form-like usage in modal_form.html * adds css enhancements for focused input fields * adds BaseModalForm as specification to BaseForm, which inherits the BSModalForm class as well * adds translations
This commit is contained in:
+42
-1
@@ -1,9 +1,12 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.forms import NewPaymentForm
|
||||
from compensation.models import Compensation, EcoAccount
|
||||
from compensation.tables import CompensationTable, EcoAccountTable
|
||||
from intervention.models import Intervention
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import *
|
||||
|
||||
@@ -108,3 +111,41 @@ def account_open_view(request: HttpRequest, id: str):
|
||||
def account_remove_view(request: HttpRequest, id: str):
|
||||
# ToDo
|
||||
pass
|
||||
|
||||
|
||||
@login_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:
|
||||
|
||||
"""
|
||||
template = "modal/modal_form.html"
|
||||
intervention = get_object_or_404(Intervention, id=intervention_id)
|
||||
form = NewPaymentForm(request.POST or None, intervention=intervention, request=request)
|
||||
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,
|
||||
_("There was an error on this form.")
|
||||
)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user