Skip to content

Commit

Permalink
fix: label stats in report pdf
Browse files Browse the repository at this point in the history
Reviewed-by: andriacap
  • Loading branch information
andriacap authored and Pierre-Narcisi committed Mar 7, 2024
1 parent 210ac50 commit f3d4a3b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion backend/geonature/core/imports/routes/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,15 @@ def export_pdf(scope, imprt):
"""
if not imprt.has_instance_permission(scope):
raise Forbidden
ctx = imprt.as_dict(fields=["errors", "errors.type", "errors.entity", "dataset.dataset_name"])
ctx = imprt.as_dict(
fields=[
"errors",
"errors.type",
"errors.entity",
"dataset.dataset_name",
"destination.statistics_labels",
]
)

ctx["map"] = request.form.get("map")
ctx["chart"] = request.form.get("chart")
Expand All @@ -656,6 +664,14 @@ def export_pdf(scope, imprt):
"report",
]
ctx["url"] = "/".join(url_list)

ctx["statistics_formated"] = {}

for label_dict in ctx["destination"]["statistics_labels"]:
key = label_dict["value"]
if label_dict["key"] in ctx["statistics"]:
ctx["statistics_formated"][key] = ctx["statistics"][label_dict["key"]]

pdf_file = generate_pdf_from_template("import_template_pdf.html", ctx)
return send_file(
BytesIO(pdf_file),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h5> Nom du fichier d'import : {{ data.full_file_name }} </h5>
</tr>
</thead>
<tbody>
{% for key, value in data.statistics.items() %}
{% for key, value in data.statistics_formated.items() %}
<tr>
<td>{{ key|capitalize }}</td>
<td>{{ value }}</td>
Expand Down

0 comments on commit f3d4a3b

Please sign in to comment.