2022-08-19 07:34:09 +02:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: ksp-servicestelle@sgdnord.rlp.de
|
|
|
|
Created on: 19.08.22
|
|
|
|
|
|
|
|
"""
|
|
|
|
from django.http import HttpRequest
|
|
|
|
from django.shortcuts import get_object_or_404, render
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
|
|
|
from intervention.models import Intervention
|
|
|
|
from konova.contexts import BaseContext
|
|
|
|
from konova.forms import SimpleGeomForm
|
|
|
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
|
|
|
from konova.utils.generators import generate_qr_code
|
|
|
|
|
|
|
|
|
2023-03-22 08:54:23 +01:00
|
|
|
def report_view(request: HttpRequest, id: str):
|
2022-08-19 07:34:09 +02:00
|
|
|
""" Renders the public report view
|
|
|
|
|
|
|
|
Args:
|
|
|
|
request (HttpRequest): The incoming request
|
|
|
|
id (str): The id of the intervention
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
template = "intervention/report/report.html"
|
|
|
|
intervention = get_object_or_404(Intervention, id=id)
|
|
|
|
|
|
|
|
tab_title = _("Report {}").format(intervention.identifier)
|
|
|
|
# If intervention is not recorded (yet or currently) we need to render another template without any data
|
|
|
|
if not intervention.is_ready_for_publish():
|
|
|
|
template = "report/unavailable.html"
|
|
|
|
context = {
|
|
|
|
TAB_TITLE_IDENTIFIER: tab_title,
|
|
|
|
}
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
return render(request, template, context)
|
|
|
|
|
|
|
|
# Prepare data for map viewer
|
|
|
|
geom_form = SimpleGeomForm(
|
|
|
|
instance=intervention
|
|
|
|
)
|
|
|
|
parcels = intervention.get_underlying_parcels()
|
|
|
|
|
|
|
|
distinct_deductions = intervention.deductions.all().distinct(
|
|
|
|
"account"
|
|
|
|
)
|
|
|
|
qrcode_url = request.build_absolute_uri(reverse("intervention:report", args=(id,)))
|
|
|
|
qrcode_img = generate_qr_code(qrcode_url, 10)
|
|
|
|
qrcode_lanis_url = intervention.get_LANIS_link()
|
|
|
|
qrcode_img_lanis = generate_qr_code(qrcode_lanis_url, 7)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
"obj": intervention,
|
|
|
|
"deductions": distinct_deductions,
|
|
|
|
"qrcode": {
|
|
|
|
"img": qrcode_img,
|
|
|
|
"url": qrcode_url,
|
|
|
|
},
|
|
|
|
"qrcode_lanis": {
|
|
|
|
"img": qrcode_img_lanis,
|
|
|
|
"url": qrcode_lanis_url,
|
|
|
|
},
|
|
|
|
"geom_form": geom_form,
|
|
|
|
"parcels": parcels,
|
2022-12-12 13:09:17 +01:00
|
|
|
"tables_scrollable": False,
|
2022-08-19 07:34:09 +02:00
|
|
|
TAB_TITLE_IDENTIFIER: tab_title,
|
|
|
|
}
|
|
|
|
context = BaseContext(request, context).context
|
|
|
|
return render(request, template, context)
|