Skip to content

Commit

Permalink
Merge pull request #228 from mvergez/feat/report
Browse files Browse the repository at this point in the history
Feat/report-158
  • Loading branch information
DonovanMaillard authored Sep 1, 2021
2 parents 5663e1e + 00a39ed commit 25950e6
Show file tree
Hide file tree
Showing 18 changed files with 1,159 additions and 127 deletions.
5 changes: 4 additions & 1 deletion backend/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

from .api_error import GeonatureImportApiError

blueprint = Blueprint("import", __name__)
blueprint = Blueprint("import",
__name__,
template_folder='templates'
)

from .routes import (
checks_and_transformations,
Expand Down
42 changes: 37 additions & 5 deletions backend/routes/imports.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""
Routes to manage import (import list, cancel import, import info...)
"""
from flask import request, current_app
from os import path
from pathlib import Path
from flask import request, current_app, render_template, send_file
from sqlalchemy.orm import exc as SQLAlchelyExc
from sqlalchemy import or_
from urllib.parse import urljoin
from functools import reduce

from pypnusershub.db.models import User
from pypnusershub.db.tools import InsufficientRightsError
Expand All @@ -18,6 +22,7 @@
TSources,
)
from geonature.core.gn_meta.models import TDatasets
import geonature.utils.filemanager as fm

from ..api_error import GeonatureImportApiError

Expand All @@ -32,6 +37,8 @@
set_imports_table_name,
get_table_info,
get_table_names,
get_table_name,
get_valid_bbox,
)
from ..utils.clean_names import *
from ..utils.utils import get_pk_name
Expand Down Expand Up @@ -87,10 +94,7 @@ def update_import(id_import):
@permissions.check_cruved_scope("R", module_code="IMPORT")
@json_resp
def get_one_import(import_id):
import_obj = TImports.query.get(import_id)
if import_obj:
return import_obj.to_dict()
return None
return get_import(import_id)


@blueprint.route("/by_dataset/<int:id_dataset>", methods=["GET"])
Expand Down Expand Up @@ -256,3 +260,31 @@ def get_import_columns_name(id_import):
col_names.remove(get_pk_name(blueprint.config["PREFIX"]))

return col_names


def get_import(id_import:int):
import_obj = TImports.query.get(id_import)
if import_obj:
return import_obj.to_dict()
return None

@blueprint.route("/export_pdf/<int:id_import>", methods=["POST"])
@permissions.check_cruved_scope("R", module_code="IMPORT")
def download(id_import):
"""
Downloads the report in pdf format
"""
filename = "rapport.pdf"
dataset = get_import(id_import=id_import)
dataset['map'] = request.form.get('map')
dataset['chart'] = request.form.get('chart')

url_list = [current_app.config['URL_APPLICATION'],
'#',
current_app.config['IMPORT'].get('MODULE_URL', "").replace('/',''),
'report',
str(dataset.get('id_import', 0))]
dataset['url'] = '/'.join(url_list)
pdf_file = fm.generate_pdf("import_template_pdf.html", dataset, filename)
pdf_file_posix = Path(pdf_file)
return send_file(pdf_file_posix, as_attachment=True)
239 changes: 239 additions & 0 deletions backend/templates/import_template_pdf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>Export rapport d'import</title>
</head>

<body>
<div class="header">
<link
rel="stylesheet"
type="text/css"
href="{{url_for('static', filename='css/metadata_pdf.css')}}"
>
<link
rel="stylesheet"
type="text/css"
href="{{url_for('static', filename='css/custom.css')}}"
>
<img
class="bandeau"
src="{{url_for('static', filename='images/Bandeau_pdf.png')}}"
alt="Bandeau"
>
<img
class="logo"
src="{{url_for('static', filename='images/logo_structure.jpg')}}"
alt="Logo"
>
</div>
<div class="titre">
<h5> Import ID : {{ data.id_import }} </h5>
<h5> Date d'import : {{ data.date_end_import.split(" ")[0] }} </h5>
<h5> Nom du fichier d'import : {{ data.full_file_name }} </h5>
<div class="ligne-titre ligne main-color"></div>
</div>
{% if data.taxa_count: %}
<div class="etiquettes">
<div id="taxons" class="etiquette">
<div class="etiquette-haut">
<img
class="logo-etiquette"
src="{{url_for('static', filename='images/Taxon_icon.svg')}}"
alt="taxon-icon"
>
<div class="etiquette-bas">
<small>Taxons</small>
</br>
{% if data.taxa_count: %}
{{ data.taxa_count }}
{% endif %}
</div>
</div>
</div>

<div id="data" class="etiquette">
<div class="etiquette-haut">
<img
class="logo-etiquette"
src="{{url_for('static', filename='images/Donnee_icon.svg')}}"
alt="donnee-icon"
>
<div class="etiquette-bas">
<small>Données importées/totales</small>
</br>
{% if data.import_count: %}
{{ data.import_count }} / {{ data.source_count }}
{% endif %}
</div>
</div>
</div>
<div class="zone">
<!-- <p class="zone-geographique">Périmètre géographique</p> -->
<h5 class="zone-geographique">Zone géographique</h5>
<img id="map" src="{{ data.map }}">
</div>
</div>
</div>
{% endif %}
<div class="description">
<div class="left-block">
<p class="fiche-descriptive">Fiche descriptive</p>
<div class="information">
<p class="info-titre">Identification</p>
<p class="info-contenu">
<br>
Auteur :
{% if data.author_name: %}
{{ data.author_name }}
{% endif %}
<br>
SRID :
{% if data.srid: %}
{{ data.srid }}
{% endif %}
<br>
Encodage :
{% if data.encoding: %}
{{ data.encoding }}
{% endif %}
<br>
Format :
{% if data.format_source_file: %}
{{ data.format_source_file }}
{% endif %}
<br>
Jeux de données :
{% if data.dataset_name: %}
{{ data.dataset_name }}
{% endif %}
</p>
</div>

{% if data.keywords: %}
<div class="information">
<p class="info-titre">Mots-clés</p>
<p class="info-contenu">
{{ data.keywords }}
</p>
</div>
{% endif %}
</div>
<div id="chart" class="zone">
<p class="zone-geographique">Répartition taxonomique</p>
<img src="{{ data.chart }}">
</div>
</div>
<div id="Error-block" class="information">
<p class="info-titre">Erreurs</p>
<p class="info-contenu">
<div id="errors">
<table id="error-table">
<thead>
<tr>
<th class="main-color">Type d'erreur</th>
<th class="main-color">Champ</th>
<th class="main-color">Nombre d'erreur(s)</th>
</tr>
</thead>
<tbody>
{% for error in data.errors %}
<tr>
<td>{{ error.error_type }}</td>
<td>{{ error.column_error }}</td>
<td>{{ error.id_rows | length }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</p>
</div>
<div class="footer">
<a href="{{data.url}}">Voir le rapport dans le module d'import</a>
<span>{{data.date_end_import}}</span>
</div>
</body>
<style>
/* Puts style here since I cannot make blueprint static files work...*/
.zone img {
max-width: 200px;
max-height: 100px;
}

.zone {
max-width: 400px;
max-height: 100px;
margin-left: 0px;
margin-top: 5px;
}

#chart {
margin-left: 30px;
}

h5 {
text-align: center;
}

#Error-block {
margin-top: 20px;
margin-left: 5px;
}

#errors {
margin-right: 10px;
}

#error-table {
border-collapse: collapse;
width: 100%;
}

#error-table td, #error-table th {
border: 1px solid #ddd;
padding: 8px;
}

#error-table tr:nth-child(even){background-color: #f2f2f2;}

#error-table td {
font-size: 10px;
}

#error-table th {
padding-top: 8px;
padding-bottom: 8px;
text-align: left;
color: white;
font-size: 12px;

}

#taxons {
width: 150px;
margin-top: 50px;
}

#data {
width: 350px;
margin-top: 50px;
}

.etiquettes {
display: contents;
margin: 0px 0px 0px 0px;
}

.left-block {
width: 700px;
margin-left: 5px;
}
.description {
margin-left: 0px;
width: 720px;
}
</style>
</html>
2 changes: 2 additions & 0 deletions config/conf_schema_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
# Parameter to define if the checkbox allowing to change display mode is displayed or not.
DISPLAY_CHECK_BOX_MAPPED_FIELD = True

# Defines the default value for the graph in the import report page
DEFAULT_RANK = "group2_inpn"

class GnModuleSchemaConf(Schema):
LIST_COLUMNS_FRONTEND = fields.List(fields.Dict, missing=DEFAULT_LIST_COLUMN)
Expand Down
56 changes: 0 additions & 56 deletions frontend/app/components/import_errors/import_errors.component.html

This file was deleted.

This file was deleted.

Loading

0 comments on commit 25950e6

Please # to comment.