Commit 6ef18790 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Merge branch '86_rapports_de_test' into 'frictionless_scratch'

Modifications du rapport de validation

See merge request !10
parents a46749c9 09b3e015
......@@ -3,6 +3,10 @@
## next
- fix source rows count display
- display missing required header as structure error
- restore filename display in report page
- move recommendations block before structure errors
- upgrade validata-core vesion to 0.6.0a9
## 0.4.0a20
......
......@@ -66,15 +66,25 @@
<p>
<code>
{% if source.type == 'file' %}
{{ source.filename }}
{% elif source.type == 'url' %}
<a href="{{source.url}}" target="_blank">{{source.filename}}</a>
{% if resource.type == 'file' %}
{{ resource.filename }}
{% elif resource.type == 'url' %}
<a href="{{resource.url}}" target="_blank">{{resource.filename}}</a>
{% endif %}
</code>
({{ report.table.col_count }} colonnes × {{ report.table.row_count }} lignes)
</p>
{% if report.warn_count != 0 %}
<p>
{% if report.warn_count == 1 %}
1 recommandation
{% else %}
{{ report.warn_count }} recommandations
{% endif %}
</p>
{% endif %}
{% if report.error_count == 0 %}
<p>Aucune erreur détectée</p>
{% else %}
......@@ -89,53 +99,40 @@
{% endif %}
</p>
{% endif %}
{% if report.warn_count != 0 %}
<p>
{% if report.warn_count == 1 %}
1 recommandation
{% else %}
{{ report.warn_count }} recommandations
{% endif %}
</p>
{% endif %}
</div>
</div>
</div>
</div>
</div>
<div class="mx-4">
{% if report.table.errors.structure %}
<h3 class="my-4">Erreurs de structure ({{ report.table['error-stats']['structure-errors']['count'] }})</h3>
<p>Prévisualisation du fichier source avec structure invalide (en-têtes)</p>
{# source header display #}
<div class="mb-4">
<div class="table-responsive">
<table class="table table-striped table-bordered table-sm table-hover">
<thead class="thead-light">
<tr>
{% for h, err in source_data.source_header_info %}
<th{% if err %} class="table-danger"{% endif %}>{{ h }}</th>
{% endfor %}
</tr>
</thead>
</table>
</div>
</div>
{% endif %}
</div>
{# Display body errors #}
<div class="mx-4">
{% if report.warn_count != 0 %}
{% if report.warn_count != 0 %}
<div class="mx-4 info">
<h3 class="my-4">Recommandations</h3>
<p>Afin d'assurer la conformité optimale de vos données par rapport au schéma,
merci de prendre en compte les recommandations ci-dessous :</p>
<ul>
{% for warn in report.warnings %}
<li>{{ warn.message | commonmark2html | safe}}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endif %}
{% if report.table.errors.structure %}
<div class="mx-4">
<h3 class="my-4">Erreurs de structure ({{ report.table['error-stats']['structure-errors']['count']}})</h3>
<ul>
{% for err in report.table.errors.structure %}
<li>{{ err.message | commonmark2html | safe}}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{# Display body errors #}
<div class="mx-4">
<h3 class="my-4">
{% if report.table.errors.body %}
{% set value_errors = report.table['error-stats']['body-errors'] %}
......
......@@ -7,6 +7,7 @@ import json
import logging
from collections import Counter
from datetime import datetime
from pathlib import Path
from urllib.parse import urlencode, urljoin
import frictionless
......@@ -347,6 +348,14 @@ def get_badge_url_and_message(badge):
def validate(schema_instance: SchemaInstance, validata_resource: ValidataResource):
""" Validate source and display report """
def compute_resource_info(resource: ValidataResource):
source = resource.get_source()
return {
"type": "url" if source.startswith("http") else "file",
"url": source,
"filename": Path(source).name,
}
# Parse source data once
header, rows = validata_resource.extract_tabular_data()
rows_count = len(rows)
......@@ -443,7 +452,7 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc
schema_info=schema_info,
section_title=schema_instance.section_title,
source_data=build_template_source_data(header, rows),
source=validata_resource,
resource=compute_resource_info(validata_resource),
validation_date=report_datetime.strftime("le %d/%m/%Y à %Hh%M"),
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment