Commit 659dddec authored by Christophe Benz's avatar Christophe Benz

Rationalise URL building

parent 406fe564
......@@ -3,7 +3,6 @@ import logging
import os
import re
from pathlib import Path
from urllib.parse import quote_plus
import cachecontrol
import flask
......@@ -89,12 +88,6 @@ if config.MATOMO_AUTH_TOKEN and config.MATOMO_BASE_URL and config.MATOMO_SITE_ID
blueprint = flask.Blueprint('filters', __name__)
@jinja2.contextfilter
@blueprint.app_template_filter()
def urlencode(context, value):
return quote_plus(value)
@jinja2.contextfilter
@blueprint.app_template_filter()
def commonmark2html(context, value):
......
......@@ -32,7 +32,7 @@
{% if source.type == 'url' %}
<p class="hidden-print">
<a class="btn btn-outline-secondary" href="{{ pdf_report_url }}&url={{source.url|urlencode}}" target="_blank">
<a class="btn btn-outline-secondary" href="{{ pdf_report_url }}" target="_blank">
Télécharger en PDF
</a>
</p>
......
......@@ -11,7 +11,7 @@ import tempfile
from datetime import datetime
from operator import itemgetter
from pathlib import Path
from urllib.parse import quote_plus, urlencode
from urllib.parse import urlencode, urljoin
import requests
import tableschema
......@@ -321,8 +321,11 @@ def get_badge_url_and_message(badge):
"""Gets badge url from badge information"""
msg, color = compute_badge_message_and_color(badge)
return ('{}static/v1.svg?label=Validata&message={}&color={}'.format(
config.SHIELDS_IO_BASE_URL, quote_plus(msg), color), msg)
badge_url = "{}?{}".format(
urljoin(config.SHIELDS_IO_BASE_URL, '/static/v1.svg'),
urlencode({"label": "Validata", "message": msg, "color": color}),
)
return (badge_url, msg)
def validate(schema_instance: SchemaInstance, source: ValidataResource):
......@@ -384,7 +387,11 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource):
# Display report to the user
validator_form_url = compute_validation_form_url(schema_instance.request_parameters())
schema_info = compute_schema_info(schema_instance.schema, schema_instance.url)
pdf_report_url = url_for('pdf_report') + '?' + urlencode(schema_instance.request_parameters())
pdf_report_url = "{}?{}".format(url_for('pdf_report'),
urlencode({
**schema_instance.request_parameters(),
"url": source.url,
}))
return render_template('validation_report.html',
badge_msg=badge_msg,
......@@ -471,7 +478,7 @@ def pdf_report():
'url': url_param,
**schema_instance.request_parameters()
}
validation_url = base_url + '?' + urlencode(parameter_dict)
validation_url = "{}?{}".format(base_url, urlencode(parameter_dict))
# Create temp file to save validation report
with tempfile.NamedTemporaryFile(prefix='validata_{}_report_'.format(datetime.now().timestamp()), suffix='.pdf') as tmpfile:
......@@ -521,8 +528,7 @@ def compute_schema_info(table_schema: tableschema.Schema, schema_url):
def compute_validation_form_url(request_parameters: dict):
"""Computes validation form url with schema URL parameter"""
url = url_for('custom_validator')
param_list = ['{}={}'.format(k, quote_plus(v)) for k, v in request_parameters.items()]
return "{}?{}".format(url, '&'.join(param_list))
return "{}?{}".format(url, urlencode(request_parameters))
@app.route('/table-schema', methods=['GET', 'POST'])
......
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