From 8e95e980a32969770108c0033e3e224b18314822 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 22 Feb 2023 10:53:25 +0100 Subject: [PATCH] # Reduces db access * reduces number of queries performed on detail views of intervention, compensation and eco_account * renders deductable_rest of eco account beneath progressbar on eco account index view * clarifies ordering logic of related column --- compensation/tables/eco_account.py | 2 ++ compensation/views/compensation/compensation.py | 6 +++++- intervention/views/intervention.py | 7 ++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/compensation/tables/eco_account.py b/compensation/tables/eco_account.py index da1444e..64171db 100644 --- a/compensation/tables/eco_account.py +++ b/compensation/tables/eco_account.py @@ -8,6 +8,7 @@ Created on: 18.08.22 from django.http import HttpRequest from django.template.loader import render_to_string from django.urls import reverse +from django.utils.formats import number_format from django.utils.html import format_html from django.utils.translation import gettext_lazy as _ @@ -111,6 +112,7 @@ class EcoAccountTable(BaseTable, TableRenderMixin, TableOrderMixin): except ZeroDivisionError: value_relative = 0 html = render_to_string("konova/widgets/progressbar.html", {"value": value_relative}) + html += f"{number_format(record.deductable_rest, decimal_pos=2)} m²" return format_html(html) def render_r(self, value, record: EcoAccount): diff --git a/compensation/views/compensation/compensation.py b/compensation/views/compensation/compensation.py index d5d7715..e37dc9b 100644 --- a/compensation/views/compensation/compensation.py +++ b/compensation/views/compensation/compensation.py @@ -204,7 +204,11 @@ def detail_view(request: HttpRequest, id: str): """ template = "compensation/detail/compensation/view.html" comp = get_object_or_404( - Compensation, + Compensation.objects.select_related( + "modified", + "created", + "geometry" + ), id=id, deleted=None, intervention__deleted=None, diff --git a/intervention/views/intervention.py b/intervention/views/intervention.py index 0dd59bd..29230f4 100644 --- a/intervention/views/intervention.py +++ b/intervention/views/intervention.py @@ -142,6 +142,8 @@ def detail_view(request: HttpRequest, id: str): "geometry", "legal", "responsible", + ).prefetch_related( + "legal__revocations", ), id=id, deleted=None @@ -158,7 +160,10 @@ def detail_view(request: HttpRequest, id: str): last_checked = intervention.get_last_checked_action() last_checked_tooltip = "" if last_checked: - last_checked_tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format(last_checked.get_timestamp_str_formatted(), last_checked.user) + last_checked_tooltip = DATA_CHECKED_PREVIOUSLY_TEMPLATE.format( + last_checked.get_timestamp_str_formatted(), + last_checked.user + ) has_payment_without_document = intervention.payments.exists() and not intervention.get_documents()[1].exists()