diff --git a/.env.example b/.env.example
index 7e99190e3ae065ade2cedcdc680eeb40fbfab4b8..cd11f90477a3a9b4b8a1fcbac9bb28ff1ae3705e 100644
--- a/.env.example
+++ b/.env.example
@@ -5,8 +5,8 @@ LOG_LEVEL="INFO"
# For production deployment, see http://flask.pocoo.org/docs/1.0/tutorial/deploy/#configure-the-secret-key
SECRET_KEY="dev"
-# Comment the two following lines to disable "badge" generation.
-BADGE_CONFIG_URL="https://git.opendatafrance.net/validata/validata-badge/raw/master/badge_conf.toml"
+# Service used to produce SVG badge
+# Comment the following line to disable badge display
SHIELDS_IO_BASE_URL="https://img.shields.io/"
# Validata API endpoint
diff --git a/validata_ui/config.py b/validata_ui/config.py
index 13ebe767429048ec8c20c62726220b735a6b09be..498cd1c74da4b6569412e25693fc12897a9fe038 100644
--- a/validata_ui/config.py
+++ b/validata_ui/config.py
@@ -28,18 +28,6 @@ API_VALIDATE_ENDPOINT = os.environ.get("API_VALIDATE_ENDPOINT") or None
if API_VALIDATE_ENDPOINT is None:
log.error("API_VALIDATE_ENDPOINT environment variable is not set, validation is not possible")
-BADGE_CONFIG_URL = os.environ.get("BADGE_CONFIG_URL") or None
-BADGE_CONFIG = None
-if BADGE_CONFIG_URL is None:
- log.warning("BADGE_CONFIG_URL environment variable is not set, disable badge feature")
-else:
- response = requests.get(BADGE_CONFIG_URL)
- if not response.ok:
- log.warning("Can't retrieve badge config from [%s], disable badge feature", BADGE_CONFIG_URL)
- else:
- BADGE_CONFIG = toml.loads(response.text)
-
-
SHIELDS_IO_BASE_URL = os.environ.get("SHIELDS_IO_BASE_URL") or None
if SHIELDS_IO_BASE_URL and not SHIELDS_IO_BASE_URL.endswith('/'):
SHIELDS_IO_BASE_URL += '/'
diff --git a/validata_ui/templates/validation_report.html b/validata_ui/templates/validation_report.html
index 12e9b85ec6389cd47000672fe1e0864768c9e548..5ec79efbde649621c7462bcd969d37d597678819 100644
--- a/validata_ui/templates/validation_report.html
+++ b/validata_ui/templates/validation_report.html
@@ -31,7 +31,9 @@
{% endif %}
{{ title }}
Validation effectuée {{ validation_date }}
+ {% if display_badge %}

+ {% endif %}
{% if print_mode %}
diff --git a/validata_ui/views.py b/validata_ui/views.py
index 1c341ed3350df3679119a9cb19239369eb3e6889..19c1c952bbdfef49ae168694d63c9cbd82fbfc38 100644
--- a/validata_ui/views.py
+++ b/validata_ui/views.py
@@ -20,7 +20,7 @@ from backports.datetime_fromisoformat import MonkeyPatch
from commonmark import commonmark
from flask import make_response, redirect, render_template, request, url_for
-from validata_core import compute_badge, messages
+from validata_core import messages
from . import app, config, schema_catalog_map, schema_from_url
from .ui_util import flash_error, flash_warning
@@ -34,13 +34,13 @@ log = logging.getLogger(__name__)
class SchemaInstance():
"""Handly class to handle schema information"""
- def __init__(self, url=None, name=None, ref=None, spec=None, versions=None, doc_url=None):
+ def __init__(self, url=None, name=None, ref=None, schema=None, versions=None, doc_url=None):
"""This function is not intended to be called directly
but via from_parameters() static method!"""
self.url = url
self.name = name
self.ref = ref
- self.spec = spec
+ self.schema = schema
self.versions = versions
self.doc_url = doc_url
@@ -88,7 +88,7 @@ class SchemaInstance():
return None
return SchemaInstance(url=schema_url, name=schema_name, ref=schema_ref,
- spec=schema_from_url(schema_url), versions=versions, doc_url=doc_url)
+ schema=schema_from_url(schema_url), versions=versions, doc_url=doc_url)
def request_parameters(self):
if self.name:
@@ -338,10 +338,13 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource):
json_response = req.json()
validata_core_report = json_response['report']
+ badge_info = json_response.get('badge')
# Computes badge from report and badge configuration
- badge = compute_badge(validata_core_report, config.BADGE_CONFIG)
- badge_url, badge_msg = get_badge_url_and_message(badge)
+ badge_url, badge_msg = None, None
+ display_badge = badge_info and config.SHIELDS_IO_BASE_URL
+ if display_badge:
+ badge_url, badge_msg = get_badge_url_and_message(badge_info)
source_errors = [
err
@@ -361,11 +364,11 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource):
report_datetime = datetime.fromisoformat(validata_core_report['date']).astimezone()
# Enhance validata_core_report
- validata_report = create_validata_ui_report(validata_core_report, schema_instance.spec)
+ validata_report = create_validata_ui_report(validata_core_report, schema_instance.schema.descriptor)
# Display report to the user
validator_form_url = compute_validation_form_url(schema_instance)
- schema_info, validator_title = compute_schema_info(schema_instance.spec, schema_instance.url)
+ schema_info, validator_title = compute_schema_info(schema_instance.schema, schema_instance.url)
pdf_report_url = url_for('pdf_report')+'?'+urlencode(schema_instance.request_parameters())
return render_template('validation_report.html', title='Rapport de validation',
schema_info=schema_info, report=validata_report,
@@ -375,7 +378,7 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource):
schema_current_version=schema_instance.ref,
doc_url=schema_instance.doc_url,
print_mode=request.args.get('print', 'false') == 'true',
- badge_url=badge_url, badge_msg=badge_msg,
+ display_badge=display_badge, badge_url=badge_url, badge_msg=badge_msg,
report_str=json.dumps(validata_report, sort_keys=True, indent=2),
breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'},
{'url': validator_form_url, 'title': validator_title},
@@ -528,7 +531,7 @@ def custom_validator():
if input_param is None:
schema_versions = schema_instance.versions
- schema_info, title = compute_schema_info(schema_instance.spec, schema_instance.url)
+ schema_info, title = compute_schema_info(schema_instance.schema, schema_instance.url)
return render_template('validation_form.html', title=title,
schema_info=schema_info, schema_versions=schema_versions,
schema_current_version=schema_instance.ref,