#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:
2021-10-14 08:21:51 +02:00
parent 354ec4c929
commit f894d6d4c5
11 changed files with 52 additions and 29 deletions

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)