Commit f41c9321 authored by Pierre Dittgen's avatar Pierre Dittgen

PDF report is ok now

parent 84c0a3a8
......@@ -36,7 +36,7 @@
{% endif %}
{% if source.type == 'url' %}
<p class="hidden-print">
<a href="{{ url_for('pdf_report', val_code=val_info.code) }}?url={{source.name|urlencode}}" target="_blank">
<a href="{{ url_for('pdf_report') }}?schema={{schema_url|urlencode}}&url={{source.name|urlencode}}" target="_blank">
Télécharger en PDF
</a>
</p>
......@@ -47,7 +47,7 @@
<div class="card bg-faded">
<div class="card-body">
<h5 class="card-title">
Schéma {{ val_info.code }}
Schéma
<span class="badge badge-primary">{{ val_info.version }}</span>
</h5>
<h6 class="card-subtitle mb-2 text-muted">{{ val_info.description }}</h6>
......@@ -62,11 +62,13 @@
</p>
{% endif %}
<p>
<a href="{{ val_info.doc_url }}" target="_blank" class="card-link">Documentation</a>
<a href="{{ schema_url }}" target="_blank" class="card-link">{{ schema_url }}</a>
</p>
<hr />
<div>
Fichier traité :
<h5 class="card-title">
Fichier traité
</h5>
{% if source_type == 'file' %}
{{ source.name }}
{% endif %}
......
......@@ -43,12 +43,6 @@ def extract_source_data(source: ValidataSource, preview_rows_nb=5):
rows = []
nb_rows = 0
# if source.scheme == 'file':
# source.scheme = 'bytes'
import ipdb
ipdb.set_trace()
options = {}
if source.format == "csv":
options['delimiter'] = csv_helpers.detect_dialect(source.source, format=source.format, scheme=source.scheme,
......@@ -300,6 +294,7 @@ def validate(schema_url, source: ValidataSource):
# Display report to the user
return render_template('validation_report.html', title='Rapport de validation',
val_info={}, report=validata_report,
schema_url=schema_url,
validation_date=report_datetime.strftime('le %d/%m/%Y à %Hh%M'),
source=source, source_type=source.type, source_data=source_data,
print_mode=request.args.get('print', 'false') == 'true',
......@@ -352,24 +347,25 @@ def validators():
return redirect(url_for('home'))
@app.route('/pdf/<val_code>')
def pdf_report(val_code):
@app.route('/pdf')
def pdf_report():
"""PDF report generation"""
err_prefix = 'Erreur de génération du rapport PDF'
if not ValidatorHelper.schema_exist(val_code):
flash_error(err_prefix + ': schéma inconnu')
return redirect(url_for('scdl_validator', val_code=val_code))
url_param = request.args.get('url')
if not url_param:
flash_error(err_prefix + ': URL non fournie')
return redirect(url_for('scdl_validator', val_code=val_code))
return redirect(url_for('home'))
schema_param = request.args.get('schema')
if not schema_param:
flash_error(err_prefix + ': URL de schema non fournie')
return redirect(url_for('home'))
validation_url = '{}?input=url&print=true&url={}'.format(url_for('scdl_validator', val_code=val_code, _external=True),
quote_plus(url_param))
validation_url = '{}?input=url&print=true&url={}&schema={}'.format(url_for('custom_validator', _external=True),
quote_plus(url_param), quote_plus(schema_param))
with tempfile.NamedTemporaryFile(prefix='validata_{}_report_'.format(val_code), suffix='.pdf') as tmpfile:
with tempfile.NamedTemporaryFile(prefix='validata_{}_report_'.format(datetime.now().timestamp()), suffix='.pdf') as tmpfile:
tmp_pdf_report = Path(tmpfile.name)
cmd = ['chromium', '--headless', '--disable-gpu',
......@@ -380,10 +376,9 @@ def pdf_report(val_code):
log.error("Command %r returned an error: %r", cmd, result.stdout.decode('utf-8'))
if tmp_pdf_report.exists():
tmp_pdf_report.unlink()
return redirect(url_for('scdl_validator', val_code=val_code))
return redirect(url_for('home'))
pdf_filename = 'Rapport de validation {} {}.pdf'.format(val_code,
datetime.now().strftime('%d-%m-%Y %Hh%M'))
pdf_filename = 'Rapport de validation {}.pdf'.format(datetime.now().strftime('%d-%m-%Y %Hh%M'))
response = make_response(tmp_pdf_report.read_bytes())
response.headers.set('Content-disposition', 'attachment', filename=pdf_filename)
response.headers.set('Content-type', 'application/pdf')
......
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