3dc2af4b7c
* renames eco_withdraws to withdraws * adds EcoAccountTableFilter * changes percentage withdraw to surface withdraw --> renames amount to surface * updates EcoAccountTable * adds column for rendering rest of available account using a progress bar * adds progressbar.html to konova/custom_widgets * adds/updates translations
103 lines
2.4 KiB
Python
103 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.auth.decorators import login_required
|
|
from django.core.exceptions import ObjectDoesNotExist
|
|
from django.http import HttpRequest, Http404
|
|
from django.shortcuts import render, get_object_or_404
|
|
|
|
from compensation.models import EcoAccount
|
|
from compensation.tables import EcoAccountTable
|
|
from konova.contexts import BaseContext
|
|
from konova.decorators import any_group_check, default_group_required
|
|
from konova.forms import RemoveModalForm
|
|
|
|
|
|
@login_required
|
|
@any_group_check
|
|
def account_index_view(request: HttpRequest):
|
|
"""
|
|
Renders the index view for eco accounts
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
|
|
Returns:
|
|
A rendered view
|
|
"""
|
|
template = "generic_index.html"
|
|
user = request.user
|
|
eco_accounts = EcoAccount.objects.filter(
|
|
deleted=None,
|
|
)
|
|
table = EcoAccountTable(
|
|
request=request,
|
|
queryset=eco_accounts
|
|
)
|
|
context = {
|
|
"table": table,
|
|
}
|
|
context = BaseContext(request, context).context
|
|
return render(request, template, context)
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
def account_new_view(request: HttpRequest):
|
|
# ToDo
|
|
pass
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
def account_edit_view(request: HttpRequest, id: str):
|
|
# ToDo
|
|
pass
|
|
|
|
|
|
@login_required
|
|
@any_group_check
|
|
def account_open_view(request: HttpRequest, id: str):
|
|
# ToDo
|
|
pass
|
|
|
|
|
|
@login_required
|
|
def account_remove_view(request: HttpRequest, id: str):
|
|
# ToDo
|
|
pass
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
@default_group_required
|
|
def withdraw_remove_view(request: HttpRequest, id: str, withdraw_id: str):
|
|
""" Renders a modal view for removing withdraws
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
id (str): The eco account's id
|
|
withdraw_id (str): The withdraw's id
|
|
|
|
Returns:
|
|
|
|
"""
|
|
acc = get_object_or_404(EcoAccount, id=id)
|
|
try:
|
|
eco_withdraw = acc.withdraws.get(id=withdraw_id)
|
|
except ObjectDoesNotExist:
|
|
raise Http404("Unknown withdraw")
|
|
|
|
form = RemoveModalForm(request.POST or None, instance=eco_withdraw, user=request.user)
|
|
return form.process_request(
|
|
request=request,
|
|
msg_success=_("Withdraw removed")
|
|
)
|
|
|