EcoAccount detail
* adds detail view for eco account * adds withdraw detail view to eco acount detail * generalizes compensation/includes templates to be reusable for eco-accounts * moves is_shared_with() check to class BaseObject * adds/updates translations
This commit is contained in:
@@ -84,7 +84,7 @@ def open_view(request: HttpRequest, id: str):
|
||||
diff_states = abs(sum_before_states - sum_after_states)
|
||||
|
||||
context = {
|
||||
"comp": comp,
|
||||
"obj": comp,
|
||||
"geom_form": geom_form,
|
||||
"has_access": is_data_shared,
|
||||
"before_states": before_states,
|
||||
@@ -142,6 +142,8 @@ def remove_view(request: HttpRequest, id: str):
|
||||
msg_success=_("Compensation removed"),
|
||||
redirect_url="",
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def new_document_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
|
||||
@@ -5,6 +5,7 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 09.08.21
|
||||
|
||||
"""
|
||||
from django.db.models import Sum
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
@@ -15,7 +16,9 @@ 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
|
||||
from konova.forms import RemoveModalForm, SimpleGeomForm
|
||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -63,8 +66,52 @@ def account_edit_view(request: HttpRequest, id: str):
|
||||
@login_required
|
||||
@any_group_check
|
||||
def account_open_view(request: HttpRequest, id: str):
|
||||
# ToDo
|
||||
pass
|
||||
""" Renders a detail view for a compensation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
template = "compensation/detail/eco_account/view.html"
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
geom_form = SimpleGeomForm(instance=acc)
|
||||
_user = request.user
|
||||
is_data_shared = acc.is_shared_with(_user)
|
||||
|
||||
# Order states according to surface
|
||||
before_states = acc.before_states.all().order_by("-surface")
|
||||
after_states = acc.after_states.all().order_by("-surface")
|
||||
|
||||
# Precalculate logical errors between before- and after-states
|
||||
# Sum() returns None in case of no states, so we catch that and replace it with 0 for easier handling
|
||||
sum_before_states = before_states.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
sum_after_states = after_states.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
diff_states = abs(sum_before_states - sum_after_states)
|
||||
|
||||
# Calculate rest of available surface for withdraws
|
||||
withdraws = acc.withdraws.all()
|
||||
withdraw_surfaces = withdraws.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
available = int(((sum_after_states - withdraw_surfaces) / sum_after_states) * 100)
|
||||
|
||||
context = {
|
||||
"obj": acc,
|
||||
"geom_form": geom_form,
|
||||
"has_access": is_data_shared,
|
||||
"before_states": before_states,
|
||||
"after_states": after_states,
|
||||
"sum_before_states": sum_before_states,
|
||||
"sum_after_states": sum_after_states,
|
||||
"available": available,
|
||||
"diff_states": diff_states,
|
||||
"is_default_member": in_group(_user, DEFAULT_GROUP),
|
||||
"is_zb_member": in_group(_user, ZB_GROUP),
|
||||
"is_ets_member": in_group(_user, ETS_GROUP),
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user