# Report view refactoring
* refactors function based report views into class based for EIV, OEK, EMA, KOM * introduces BaseReportView for proper inheritance of shared logic * refactors generating of qr codes into proper class
This commit is contained in:
@@ -18,7 +18,7 @@ from intervention.views.intervention import new_view, detail_view, edit_view, re
|
||||
InterventionIndexView, InterventionIdentifierGeneratorView
|
||||
from intervention.views.log import InterventionLogView
|
||||
from intervention.views.record import InterventionRecordView
|
||||
from intervention.views.report import report_view
|
||||
from intervention.views.report import InterventionReportView
|
||||
from intervention.views.resubmission import InterventionResubmissionView
|
||||
from intervention.views.revocation import new_revocation_view, edit_revocation_view, remove_revocation_view, \
|
||||
get_revocation_view
|
||||
@@ -37,7 +37,7 @@ urlpatterns = [
|
||||
path('<id>/share', InterventionShareFormView.as_view(), name='share-form'),
|
||||
path('<id>/check', check_view, name='check'),
|
||||
path('<id>/record', InterventionRecordView.as_view(), name='record'),
|
||||
path('<id>/report', report_view, name='report'),
|
||||
path('<id>/report', InterventionReportView.as_view(), name='report'),
|
||||
path('<id>/resub', InterventionResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
# Compensations
|
||||
|
||||
@@ -5,72 +5,41 @@ 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.decorators import uuid_required
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.generators import generate_qr_code
|
||||
from konova.sub_settings.django_settings import BASE_URL
|
||||
from konova.utils.qrcode import QrCode
|
||||
from konova.views.report import BaseReportView
|
||||
|
||||
|
||||
@uuid_required
|
||||
def report_view(request: HttpRequest, id: str):
|
||||
""" Renders the public report view
|
||||
class InterventionReportView(BaseReportView):
|
||||
_TEMPLATE = 'intervention/report/report.html'
|
||||
_MODEL = Intervention
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The id of the intervention
|
||||
def _get_report_context(self, obj: Intervention):
|
||||
""" Returns the specific context needed for an intervention report
|
||||
|
||||
Returns:
|
||||
Args:
|
||||
obj (Intervention): The object for the report
|
||||
|
||||
"""
|
||||
template = "intervention/report/report.html"
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
Returns:
|
||||
dict: The object specific context for rendering the report
|
||||
"""
|
||||
distinct_deductions = obj.deductions.all().distinct("account")
|
||||
report_url = BASE_URL + reverse("intervention:report", args=(obj.id,))
|
||||
qrcode_report = QrCode(report_url, 10)
|
||||
qrcode_lanis = QrCode(obj.get_LANIS_link(), 7)
|
||||
|
||||
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,
|
||||
return {
|
||||
"deductions": distinct_deductions,
|
||||
"qrcode": {
|
||||
"img": qrcode_report.get_img(),
|
||||
"url": qrcode_report.get_content(),
|
||||
},
|
||||
"qrcode_lanis": {
|
||||
"img": qrcode_lanis.get_img(),
|
||||
"url": qrcode_lanis.get_content(),
|
||||
},
|
||||
"tables_scrollable": False,
|
||||
}
|
||||
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,
|
||||
"tables_scrollable": False,
|
||||
TAB_TITLE_IDENTIFIER: tab_title,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
Reference in New Issue
Block a user