# 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:
@@ -14,7 +14,7 @@ from ema.views.ema import new_view, detail_view, edit_view, remove_view, EmaInde
|
||||
EmaIdentifierGeneratorView
|
||||
from ema.views.log import EmaLogView
|
||||
from ema.views.record import EmaRecordView
|
||||
from ema.views.report import report_view
|
||||
from ema.views.report import EmaReportView
|
||||
from ema.views.resubmission import EmaResubmissionView
|
||||
from ema.views.share import EmaShareFormView, EmaShareByTokenView
|
||||
from ema.views.state import NewEmaStateView, EditEmaStateView, RemoveEmaStateView
|
||||
@@ -29,7 +29,7 @@ urlpatterns = [
|
||||
path('<id>/edit', edit_view, name='edit'),
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
path('<id>/record', EmaRecordView.as_view(), name='record'),
|
||||
path('<id>/report', report_view, name='report'),
|
||||
path('<id>/report', EmaReportView.as_view(), name='report'),
|
||||
path('<id>/resub', EmaResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
path('<id>/state/new', NewEmaStateView.as_view(), name='new-state'),
|
||||
|
||||
@@ -5,77 +5,36 @@ 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 compensation.views.compensation.report import BaseCompensationReportView
|
||||
from ema.models import Ema
|
||||
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
|
||||
|
||||
@uuid_required
|
||||
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
|
||||
class EmaReportView(BaseCompensationReportView):
|
||||
_TEMPLATE = "ema/report/report.html"
|
||||
_MODEL = Ema
|
||||
|
||||
Returns:
|
||||
def _get_report_context(self, obj):
|
||||
report_url = BASE_URL + reverse("ema:report", args=(obj.id,))
|
||||
qrcode_report = QrCode(report_url, 10)
|
||||
qrcode_lanis = QrCode(obj.get_LANIS_link(), 7)
|
||||
|
||||
"""
|
||||
# Reuse the compensation report template since EMAs are structurally identical
|
||||
template = "ema/report/report.html"
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
generic_compensation_report_context = self._get_compensation_report_context(obj)
|
||||
|
||||
tab_title = _("Report {}").format(ema.identifier)
|
||||
# If intervention is not recorded (yet or currently) we need to render another template without any data
|
||||
if not ema.is_ready_for_publish():
|
||||
template = "report/unavailable.html"
|
||||
context = {
|
||||
TAB_TITLE_IDENTIFIER: tab_title,
|
||||
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
|
||||
"tables_scrollable": False,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
# Prepare data for map viewer
|
||||
geom_form = SimpleGeomForm(
|
||||
instance=ema,
|
||||
)
|
||||
parcels = ema.get_underlying_parcels()
|
||||
|
||||
qrcode_url = request.build_absolute_uri(reverse("ema:report", args=(id,)))
|
||||
qrcode_img = generate_qr_code(qrcode_url, 10)
|
||||
qrcode_lanis_url = ema.get_LANIS_link()
|
||||
qrcode_img_lanis = generate_qr_code(qrcode_lanis_url, 7)
|
||||
|
||||
# Order states by surface
|
||||
before_states = ema.before_states.all().order_by("-surface").prefetch_related("biotope_type")
|
||||
after_states = ema.after_states.all().order_by("-surface").prefetch_related("biotope_type")
|
||||
actions = ema.actions.all().prefetch_related("action_type")
|
||||
|
||||
context = {
|
||||
"obj": ema,
|
||||
"qrcode": {
|
||||
"img": qrcode_img,
|
||||
"url": qrcode_url
|
||||
},
|
||||
"qrcode_lanis": {
|
||||
"img": qrcode_img_lanis,
|
||||
"url": qrcode_lanis_url
|
||||
},
|
||||
"is_entry_shared": False, # disables action buttons during rendering
|
||||
"before_states": before_states,
|
||||
"after_states": after_states,
|
||||
"geom_form": geom_form,
|
||||
"parcels": parcels,
|
||||
"actions": actions,
|
||||
"tables_scrollable": False,
|
||||
TAB_TITLE_IDENTIFIER: tab_title,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
report_context.update(generic_compensation_report_context)
|
||||
return report_context
|
||||
Reference in New Issue
Block a user