""" Author: Michel Peltriaux Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany Contact: ksp-servicestelle@sgdnord.rlp.de Created on: 19.08.22 """ from django.urls import reverse from compensation.models import EcoAccount from compensation.views.compensation.report import BaseCompensationReportView from konova.sub_settings.django_settings import BASE_URL from konova.utils.qrcode import QrCode class EcoAccountReportView(BaseCompensationReportView): _MODEL = EcoAccount _TEMPLATE = "compensation/report/eco_account/report.html" def _get_report_context(self, obj): report_url = BASE_URL + reverse("compensation:acc:report", args=(obj.id,)) qrcode_report = QrCode(report_url, 10) qrcode_lanis = QrCode(obj.get_LANIS_link(), 7) # Reduce amount of db fetched data to the bare minimum we need in the template (deduction's intervention id and identifier) deductions = obj.deductions.all() \ .distinct("intervention") \ .select_related("intervention") \ .values_list("intervention__id", "intervention__identifier", "intervention__title", named=True) report_context = { "qrcode": { "img": qrcode_report.get_img(), "url": qrcode_report.get_content(), }, "qrcode_lanis": { "img": qrcode_lanis.get_img(), "url": qrcode_lanis.get_content(), }, "is_entry_shared": False, # disables action buttons during rendering "deductions": deductions, "tables_scrollable": False, } report_context.update(self._get_compensation_report_context(obj)) return report_context