Commit 83d52056 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

fix badge

parent d68b694a
......@@ -5,6 +5,9 @@ LOG_LEVEL="INFO"
# For production deployment, see http://flask.pocoo.org/docs/1.0/tutorial/deploy/#configure-the-secret-key
SECRET_KEY="dev"
# Badge config
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/"
......
# Changelog
## next
- Fix badge display
## 0.4.0a0
- Migrate to new library [frictionless-py](https://github.com/frictionlessdata/frictionless-py) that replaces `goodtables-py`.
......
......@@ -29,6 +29,17 @@ logging.basicConfig(
SECRET_KEY = os.environ.get("SECRET_KEY") or None
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:
SHIELDS_IO_BASE_URL = without_trailing_slash(SHIELDS_IO_BASE_URL)
......
......@@ -559,7 +559,7 @@ def compute_badge_message_and_color(badge):
# No body error
if body == "OK":
return (
("structure invalide", "orange")
("partiellement valide", "yellowgreen")
if structure == "WARN"
else ("valide", "green")
)
......@@ -593,13 +593,14 @@ def validate(schema_instance: SchemaInstance, validata_source: ValidataResource)
)
# disable badge
badge_info = None
badge_config = config.BADGE_CONFIG
# Computes badge from report and badge configuration
badge_url, badge_msg = None, None
display_badge = badge_info and config.SHIELDS_IO_BASE_URL
display_badge = badge_config and config.SHIELDS_IO_BASE_URL
if display_badge:
badge_url, badge_msg = get_badge_url_and_message(badge_info)
badge_stats = validata_core.compute_badge_metrics(validata_core_report, badge_config)
badge_url, badge_msg = get_badge_url_and_message(badge_stats)
# Source error
source_errors = [
......@@ -680,7 +681,7 @@ def retrieve_schema_catalog(section):
exception_text = "\n".join([str(arg) for arg in exc.args])
return f"""{err_msg}
return f"""{err_msg}
<div class="float-right">
<button type="button" class="btn btn-info btn-xs" data-toggle="collapse" data-target="#exception_info">détails</button>
</div>
......
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