#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
This commit is contained in:
mpeltriaux 2021-10-14 08:21:51 +02:00
parent 193ba4c658
commit ce74d011f6
11 changed files with 52 additions and 29 deletions

View File

@ -4,7 +4,7 @@
<div class="row">
<div class="col-sm-6">
<h5>
<span class="badge badge-light">{{obj.actions.count}}</span>
<span class="badge badge-light">{{actions.count}}</span>
{% trans 'Actions' context 'Compensation' %}
</h5>
</div>
@ -41,7 +41,7 @@
</tr>
</thead>
<tbody>
{% for action in obj.actions.all %}
{% for action in actions %}
<tr>
<td class="align-middle">
{{ action.action_type }}

View File

@ -33,9 +33,11 @@
<th scope="col">
{% trans 'Comment' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
{% trans 'Action' %}
</th>
{% endif %}
</tr>
</thead>
<tbody>

View File

@ -30,9 +30,11 @@
<th scope="col">
{% trans 'Comment' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
{% trans 'Action' %}
</th>
{% endif %}
</tr>
</thead>
<tbody>

View File

@ -4,7 +4,7 @@
<div class="row">
<div class="col-sm-6">
<h5>
<span class="badge badge-light">{{obj.before_states.count}}</span>
<span class="badge badge-light">{{before_states.count}}</span>
{% trans 'States before' %}
</h5>
</div>

View File

@ -23,10 +23,14 @@
<tr>
<th scope="row">{% trans 'Funded by' %}</th>
<td class="align-middle">
{% for funding in obj.fundings.all %}
{% with obj.fundings.all as fundings %}
{% for funding in fundings %}
<div class="badge pill-badge rlp-r-outline">{{funding.short_name}}</div>
<br>
{% empty %}
{% trans 'None' %}
{% endfor %}
{% endwith %}
</td>
</tr>
<tr>

View File

@ -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)

View File

@ -32,9 +32,11 @@
<th scope="col">
{% trans 'Title' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
{% trans 'Action' %}
</th>
{% endif %}
</tr>
</thead>
<tbody>

View File

@ -33,9 +33,11 @@
<th scope="col">
{% trans 'Created' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
{% trans 'Action' %}
</th>
{% endif %}
</tr>
</thead>
<tbody>

View File

@ -30,9 +30,11 @@
<th scope="col">
{% trans 'Comment' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
{% trans 'Action' %}
</th>
{% endif %}
</tr>
</thead>
<tbody>

View File

@ -33,9 +33,11 @@
<th scope="col">
{% trans 'Comment' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
{% trans 'Action' %}
</th>
{% endif %}
</tr>
</thead>
<tbody>

View File

@ -36,9 +36,11 @@
<th scope="col">
{% trans 'Comment' %}
</th>
<th scope="col">
{% trans 'Action' %}
</th>
{% if is_default_member and has_access %}
<th scope="col">
{% trans 'Action' %}
</th>
{% endif %}
</tr>
</thead>
<tbody>