Compensation detail view
* adds compensation detail view (WIP) * adds includes dir for related objects, similar to interventions * adds functionality for * adding/removing before_states * adding/removing after_states * adding/removing deadlines * adding/removing documents * refactors usage of BaseModalForm * holds now process_request() in base class for generic usage anywhere * adds __str__() method for some models * compensation__action is blank=True now * renamed tooltips * adds new routes for state/deadline/document handling inside of compensation/urls.py * adds precalculation of before/after_states for detail view, so users will see directly if there are missing states * removes unnecessary link for intervention detail payment * adds missing tooltips for check and record icon on detail views * refactors DeadlineTypeEnum into DeadlineType in konova/models.py, just as the django 3.x documentation suggests for model enumerations * UuidModel id field is not editable anymore in the admin interface * adds/updates translations
This commit is contained in:
+106
-5
@@ -1,17 +1,19 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models import Sum
|
||||
from django.http import HttpRequest, Http404
|
||||
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, Payment
|
||||
from compensation.forms import NewPaymentForm, NewStateModalForm, NewDeadlineModalForm
|
||||
from compensation.models import Compensation, EcoAccount, Payment, CompensationState
|
||||
from compensation.tables import CompensationTable, EcoAccountTable
|
||||
from intervention.models import Intervention
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import *
|
||||
from konova.forms import RemoveModalForm
|
||||
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -59,8 +61,40 @@ def edit_view(request: HttpRequest, id: str):
|
||||
@login_required
|
||||
@any_group_check
|
||||
def 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/view.html"
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
geom_form = SimpleGeomForm(instance=comp)
|
||||
_user = request.user
|
||||
is_data_shared = comp.intervention.is_shared_with(_user)
|
||||
|
||||
# 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 = comp.before_states.all().aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
sum_after_states = comp.after_states.all().aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
diff_states = abs(sum_before_states - sum_after_states)
|
||||
|
||||
context = {
|
||||
"comp": comp,
|
||||
"geom_form": geom_form,
|
||||
"has_access": is_data_shared,
|
||||
"is_default_member": in_group(_user, _(DEFAULT_GROUP)),
|
||||
"is_zb_member": in_group(_user, _(ZB_GROUP)),
|
||||
"is_ets_member": in_group(_user, _(ETS_GROUP)),
|
||||
"sum_before_states": sum_before_states,
|
||||
"sum_after_states": sum_after_states,
|
||||
"diff_states": diff_states,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -79,6 +113,7 @@ def remove_view(request: HttpRequest, id: str):
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=_("Compensation removed"),
|
||||
redirect_url="",
|
||||
)
|
||||
|
||||
|
||||
@@ -220,3 +255,69 @@ def withdraw_remove_view(request: HttpRequest, id: str, withdraw_id: str):
|
||||
request=request,
|
||||
msg_success=_("Withdraw removed")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def new_document_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id to which the new document will be related
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
form = NewDocumentForm(request.POST or None, request.FILES or None, instance=comp, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Document added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def state_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for a compensation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
form = NewStateModalForm(request.POST or None, instance=comp, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def deadline_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for a compensation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The compensation's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
comp = get_object_or_404(Compensation, id=id)
|
||||
form = NewDeadlineModalForm(request.POST or None, instance=comp, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Deadline added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def state_remove_view(request: HttpRequest, id: str):
|
||||
state = get_object_or_404(CompensationState, id=id)
|
||||
form = RemoveModalForm(request.POST or None, instance=state, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State removed")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user