From f894d6d4c5e8bf30ff1e390d19df88fe6dab323d Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 14 Oct 2021 08:21:51 +0200 Subject: [PATCH] #25 Public reports * prevents Actions column in tables from being rendered if there would be no buttons inside due to permission checking * enhances amount of sql requests for detail view and report view --- .../detail/compensation/includes/actions.html | 4 ++-- .../detail/compensation/includes/deadlines.html | 8 +++++--- .../detail/compensation/includes/documents.html | 8 +++++--- .../detail/compensation/includes/states-before.html | 2 +- .../compensation/report/compensation/report.html | 6 +++++- compensation/views/compensation_views.py | 13 +++++++++---- .../intervention/detail/includes/compensations.html | 8 +++++--- .../intervention/detail/includes/deductions.html | 8 +++++--- .../intervention/detail/includes/documents.html | 8 +++++--- .../intervention/detail/includes/payments.html | 8 +++++--- .../intervention/detail/includes/revocation.html | 8 +++++--- 11 files changed, 52 insertions(+), 29 deletions(-) diff --git a/compensation/templates/compensation/detail/compensation/includes/actions.html b/compensation/templates/compensation/detail/compensation/includes/actions.html index a1c77f21..08930a9c 100644 --- a/compensation/templates/compensation/detail/compensation/includes/actions.html +++ b/compensation/templates/compensation/detail/compensation/includes/actions.html @@ -4,7 +4,7 @@
- {{obj.actions.count}} + {{actions.count}} {% trans 'Actions' context 'Compensation' %}
@@ -41,7 +41,7 @@ - {% for action in obj.actions.all %} + {% for action in actions %} {{ action.action_type }} diff --git a/compensation/templates/compensation/detail/compensation/includes/deadlines.html b/compensation/templates/compensation/detail/compensation/includes/deadlines.html index 206bd7d3..4ca109f7 100644 --- a/compensation/templates/compensation/detail/compensation/includes/deadlines.html +++ b/compensation/templates/compensation/detail/compensation/includes/deadlines.html @@ -33,9 +33,11 @@ {% trans 'Comment' %} - - {% trans 'Action' %} - + {% if is_default_member and has_access %} + + {% trans 'Action' %} + + {% endif %} diff --git a/compensation/templates/compensation/detail/compensation/includes/documents.html b/compensation/templates/compensation/detail/compensation/includes/documents.html index 3548e940..7e958f6d 100644 --- a/compensation/templates/compensation/detail/compensation/includes/documents.html +++ b/compensation/templates/compensation/detail/compensation/includes/documents.html @@ -30,9 +30,11 @@ {% trans 'Comment' %} - - {% trans 'Action' %} - + {% if is_default_member and has_access %} + + {% trans 'Action' %} + + {% endif %} diff --git a/compensation/templates/compensation/detail/compensation/includes/states-before.html b/compensation/templates/compensation/detail/compensation/includes/states-before.html index a8d20251..a0c541ae 100644 --- a/compensation/templates/compensation/detail/compensation/includes/states-before.html +++ b/compensation/templates/compensation/detail/compensation/includes/states-before.html @@ -4,7 +4,7 @@
- {{obj.before_states.count}} + {{before_states.count}} {% trans 'States before' %}
diff --git a/compensation/templates/compensation/report/compensation/report.html b/compensation/templates/compensation/report/compensation/report.html index fad5573f..de8ddd15 100644 --- a/compensation/templates/compensation/report/compensation/report.html +++ b/compensation/templates/compensation/report/compensation/report.html @@ -23,10 +23,14 @@ {% trans 'Funded by' %} - {% for funding in obj.fundings.all %} + {% with obj.fundings.all as fundings %} + {% for funding in fundings %}
{{funding.short_name}}

+ {% empty %} + {% trans 'None' %} {% endfor %} + {% endwith %} diff --git a/compensation/views/compensation_views.py b/compensation/views/compensation_views.py index 3ab84c27..994e9647 100644 --- a/compensation/views/compensation_views.py +++ b/compensation/views/compensation_views.py @@ -163,8 +163,9 @@ def detail_view(request: HttpRequest, id: str): is_data_shared = comp.intervention.is_shared_with(_user) # Order states according to surface - before_states = comp.before_states.all().order_by("-surface") - after_states = comp.after_states.all().order_by("-surface") + before_states = comp.before_states.all().prefetch_related("biotope_type").order_by("-surface") + after_states = comp.after_states.all().prefetch_related("biotope_type").order_by("-surface") + actions = comp.actions.all().prefetch_related("action_type") # Precalculate logical errors between before- and after-states # Sum() returns None in case of no states, so we catch that and replace it with 0 for easier handling @@ -176,6 +177,7 @@ def detail_view(request: HttpRequest, id: str): "obj": comp, "geom_form": geom_form, "has_access": is_data_shared, + "actions": actions, "before_states": before_states, "after_states": after_states, "sum_before_states": sum_before_states, @@ -416,8 +418,10 @@ def report_view(request:HttpRequest, id: str): 7 ) # Order states by surface - before_states = comp.before_states.all().order_by("-surface") - after_states = comp.after_states.all().order_by("-surface") + before_states = comp.before_states.all().order_by("-surface").prefetch_related("biotope_type") + after_states = comp.after_states.all().order_by("-surface").prefetch_related("biotope_type") + actions = comp.actions.all().prefetch_related("action_type") + context = { "obj": comp, "qrcode": qrcode_img, @@ -426,6 +430,7 @@ def report_view(request:HttpRequest, id: str): "before_states": before_states, "after_states": after_states, "geom_form": geom_form, + "actions": actions, } context = BaseContext(request, context).context return render(request, template, context) diff --git a/intervention/templates/intervention/detail/includes/compensations.html b/intervention/templates/intervention/detail/includes/compensations.html index c54c974f..79fcaa09 100644 --- a/intervention/templates/intervention/detail/includes/compensations.html +++ b/intervention/templates/intervention/detail/includes/compensations.html @@ -32,9 +32,11 @@ {% trans 'Title' %} - - {% trans 'Action' %} - + {% if is_default_member and has_access %} + + {% trans 'Action' %} + + {% endif %} diff --git a/intervention/templates/intervention/detail/includes/deductions.html b/intervention/templates/intervention/detail/includes/deductions.html index be509998..cb2f8179 100644 --- a/intervention/templates/intervention/detail/includes/deductions.html +++ b/intervention/templates/intervention/detail/includes/deductions.html @@ -33,9 +33,11 @@ {% trans 'Created' %} - - {% trans 'Action' %} - + {% if is_default_member and has_access %} + + {% trans 'Action' %} + + {% endif %} diff --git a/intervention/templates/intervention/detail/includes/documents.html b/intervention/templates/intervention/detail/includes/documents.html index 1365edae..cc0c9a17 100644 --- a/intervention/templates/intervention/detail/includes/documents.html +++ b/intervention/templates/intervention/detail/includes/documents.html @@ -30,9 +30,11 @@ {% trans 'Comment' %} - - {% trans 'Action' %} - + {% if is_default_member and has_access %} + + {% trans 'Action' %} + + {% endif %} diff --git a/intervention/templates/intervention/detail/includes/payments.html b/intervention/templates/intervention/detail/includes/payments.html index b6b61d96..c3ab7568 100644 --- a/intervention/templates/intervention/detail/includes/payments.html +++ b/intervention/templates/intervention/detail/includes/payments.html @@ -33,9 +33,11 @@ {% trans 'Comment' %} - - {% trans 'Action' %} - + {% if is_default_member and has_access %} + + {% trans 'Action' %} + + {% endif %} diff --git a/intervention/templates/intervention/detail/includes/revocation.html b/intervention/templates/intervention/detail/includes/revocation.html index 6699f016..c9d821ff 100644 --- a/intervention/templates/intervention/detail/includes/revocation.html +++ b/intervention/templates/intervention/detail/includes/revocation.html @@ -36,9 +36,11 @@ {% trans 'Comment' %} - - {% trans 'Action' %} - + {% if is_default_member and has_access %} + + {% trans 'Action' %} + + {% endif %}