#25 Public reports

* adds public report for compensations
* adds/updates translations
* prepares EMA and eco account reports
This commit is contained in:
2021-10-13 17:35:11 +02:00
parent 7daceb947f
commit 354ec4c929
17 changed files with 303 additions and 88 deletions

View File

@@ -13,6 +13,7 @@ from konova.contexts import BaseContext
from konova.decorators import *
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm
from konova.utils.documents import get_document, remove_document
from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED
from konova.utils.user_checks import in_group
@@ -381,3 +382,50 @@ def action_remove_view(request: HttpRequest, id: str):
request,
msg_success=_("Action removed")
)
def report_view(request:HttpRequest, id: str):
""" Renders the public report view
Args:
request (HttpRequest): The incoming request
id (str): The id of the intervention
Returns:
"""
# Reuse the compensation report template since compensations are structurally identical
template = "compensation/report/compensation/report.html"
comp = get_object_or_404(Compensation, id=id)
# If intervention is not recorded (yet or currently) we need to render another template without any data
if not comp.intervention.recorded:
template = "report/unavailable.html"
return render(request, template, {})
# Prepare data for map viewer
geom_form = SimpleGeomForm(
instance=comp
)
qrcode_img = generate_qr_code(
request.build_absolute_uri(reverse("compensation:report", args=(id,))),
10
)
qrcode_img_lanis = generate_qr_code(
comp.get_LANIS_link(),
7
)
# Order states by surface
before_states = comp.before_states.all().order_by("-surface")
after_states = comp.after_states.all().order_by("-surface")
context = {
"obj": comp,
"qrcode": qrcode_img,
"qrcode_lanis": qrcode_img_lanis,
"has_access": False, # disables action buttons during rendering
"before_states": before_states,
"after_states": after_states,
"geom_form": geom_form,
}
context = BaseContext(request, context).context
return render(request, template, context)

View File

@@ -24,6 +24,7 @@ from konova.decorators import any_group_check, default_group_required, conservat
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm, RecordModalForm
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
from konova.utils.documents import get_document, remove_document
from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import IDENTIFIER_REPLACED, FORM_INVALID
from konova.utils.user_checks import in_group
@@ -432,3 +433,39 @@ def new_deduction_view(request: HttpRequest, id: str):
request,
msg_success=_("Deduction added")
)
def report_view(request:HttpRequest, id: str):
""" Renders the public report view
Args:
request (HttpRequest): The incoming request
id (str): The id of the intervention
Returns:
"""
# Reuse the compensation report template since EcoAccounts are structurally identical
template = "compensation/report/report.html"
acc = get_object_or_404(EcoAccount, id=id)
# If intervention is not recorded (yet or currently) we need to render another template without any data
if not acc.recorded:
template = "report/unavailable.html"
return render(request, template, {})
qrcode_img = generate_qr_code(
request.build_absolute_uri(reverse("compensation:acc-report", args=(id,))),
10
)
qrcode_img_lanis = generate_qr_code(
acc.get_LANIS_link(),
7
)
context = {
"obj": acc,
"qrcode": qrcode_img,
"qrcode_lanis": qrcode_img_lanis,
}
context = BaseContext(request, context).context
return render(request, template, context)