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

View File

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

View File

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

View File

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

View File

@ -23,10 +23,14 @@
<tr> <tr>
<th scope="row">{% trans 'Funded by' %}</th> <th scope="row">{% trans 'Funded by' %}</th>
<td class="align-middle"> <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> <div class="badge pill-badge rlp-r-outline">{{funding.short_name}}</div>
<br> <br>
{% empty %}
{% trans 'None' %}
{% endfor %} {% endfor %}
{% endwith %}
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -163,8 +163,9 @@ def detail_view(request: HttpRequest, id: str):
is_data_shared = comp.intervention.is_shared_with(_user) is_data_shared = comp.intervention.is_shared_with(_user)
# Order states according to surface # Order states according to surface
before_states = comp.before_states.all().order_by("-surface") before_states = comp.before_states.all().prefetch_related("biotope_type").order_by("-surface")
after_states = comp.after_states.all().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 # 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 # 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, "obj": comp,
"geom_form": geom_form, "geom_form": geom_form,
"has_access": is_data_shared, "has_access": is_data_shared,
"actions": actions,
"before_states": before_states, "before_states": before_states,
"after_states": after_states, "after_states": after_states,
"sum_before_states": sum_before_states, "sum_before_states": sum_before_states,
@ -416,8 +418,10 @@ def report_view(request:HttpRequest, id: str):
7 7
) )
# Order states by surface # Order states by surface
before_states = comp.before_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") after_states = comp.after_states.all().order_by("-surface").prefetch_related("biotope_type")
actions = comp.actions.all().prefetch_related("action_type")
context = { context = {
"obj": comp, "obj": comp,
"qrcode": qrcode_img, "qrcode": qrcode_img,
@ -426,6 +430,7 @@ def report_view(request:HttpRequest, id: str):
"before_states": before_states, "before_states": before_states,
"after_states": after_states, "after_states": after_states,
"geom_form": geom_form, "geom_form": geom_form,
"actions": actions,
} }
context = BaseContext(request, context).context context = BaseContext(request, context).context
return render(request, template, context) return render(request, template, context)

View File

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

View File

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

View File

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

View File

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

View File

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