Commit ac14b236 authored by Christophe Benz's avatar Christophe Benz

Support tags and branches with latest tag, enhance homepage config file

parent 304c0a8f
Pipeline #1066 passed with stage
in 4 minutes and 55 seconds
......@@ -8,7 +8,7 @@
{
"name": "external",
"title": "Validateurs externes",
"catalog": [
"links": [
{
"name": "inspire",
"type": "external",
......
......@@ -5,7 +5,7 @@ ezodf==0.3.2
Flask==1.0.2
Flask-Matomo==1.2.0
lxml==4.2.5
opendataschema==0.2.0
opendataschema==0.4.0
python-dotenv==0.10.1
requests==2.22.0
toml==0.10.0
......
......@@ -64,7 +64,7 @@ setup(
'tabulator',
'opendataschema >= 0.3.0, < 0.4',
'opendataschema >= 0.4.0, < 0.5',
'validata_core >= 0.3.0, < 0.4',
],
......
......@@ -20,27 +20,29 @@ log = logging.getLogger(__name__)
def generate_schema_from_url_func(session):
"""Generates a function that encloses session"""
def schema_from_url(url):
req = session.get(url)
req.raise_for_status()
schema_dict = req.json()
return tableschema.Schema(schema_dict)
def tableschema_from_url(url):
response = session.get(url)
response.raise_for_status()
descriptor = response.json()
return tableschema.Schema(descriptor)
return schema_from_url
return tableschema_from_url
caching_session = cachecontrol.CacheControl(requests.Session())
tableschema_from_url = generate_schema_from_url_func(caching_session)
# And load schema catalogs which URLs are found in homepage_config.json
schema_catalog_map = {}
if config.HOMEPAGE_CONFIG:
log.info("Initializing homepage sections...")
caching_session = cachecontrol.CacheControl(requests.Session())
schema_from_url = generate_schema_from_url_func(caching_session)
for section in config.HOMEPAGE_CONFIG['sections']:
name = section['name']
log.info('Initializing homepage section "{}"...'.format(name))
if isinstance(section['catalog'], str) and section['catalog'].startswith('http'):
url = section['catalog']
schema_catalog_map[name] = opendataschema.SchemaCatalog(url, session=caching_session)
catalog = section.get('catalog')
if catalog and isinstance(catalog, str) and catalog.startswith('http'):
schema_catalog_map[name] = opendataschema.SchemaCatalog(catalog, session=caching_session)
log.info("...done")
# Flask things
......
......@@ -5,7 +5,7 @@
{% block content %}
{% for section in config.sections %}
{% if section.name != "external" %}
{% if section.catalog %}
<div class="mb-5">
<h2 class="my-4">{{section.title}}</h2>
<form action="{{ url_for('custom_validator') }}" method="GET">
......@@ -13,8 +13,8 @@
<div class="form-group col-lg-9">
<select required name="schema_name" class="form-control">
<option disabled selected value="">Choisissez un schéma</option>
{% for val in section.catalog | sort(attribute='title') %}
<option value="{{ val.name }}">{{ val.title }}</option>
{% for item in section.catalog | sort(attribute='title') %}
<option value="{{ item.name }}">{{ item.title }}</option>
{% endfor %}
</select>
</div>
......@@ -22,7 +22,6 @@
<button type="submit" class="btn btn-primary">Valider un fichier</button>
</div>
</div>
<input type="hidden" name="schema_ref" value="master" />
</form>
</div>
{% endif %}
......@@ -55,18 +54,18 @@
</div>
{% for section in config.sections %}
{% if section.name == "external" %}
{% if section.links %}
<div class="my-5">
<h2 class="my-4">{{ section.title }}</h2>
<div class="row my-4">
{% for val in section.catalog %}
{% for item in section.links %}
<div class="col-sm-4 mb-4">
<div class="card h-100">
<div class="card-body d-flex flex-column">
<h4 class="card-title">{{ val.title }}</h4>
<p class="card-text">{{ val.description }}</p>
<h4 class="card-title">{{ item.title }}</h4>
<p class="card-text">{{ item.description }}</p>
<a
href="{{ val.website }}" target="_blank"
href="{{ item.website }}" target="_blank"
class="btn btn-outline-secondary mt-auto"
>Utiliser
<i class="fas fa-external-link-alt ml-1"></i>
......
{% macro html(schema_info, schema_versions, schema_current_version, doc_url) %}
{% macro html(schema_info, branches, tags, schema_current_version, doc_url) %}
<h2 class="card-title">
{% if schema_info.title %}
{{ schema_info.title }}
......@@ -8,14 +8,25 @@
{% endif %}
</h2>
{% if schema_versions %}
{% if branches or tags %}
<form class="form-inline my-2">
<div class="form-group">
<label for="git_ref" class="mr-2">Version</label>
<select class="form-control" id="version_select" name="git_ref">
{% for sv in schema_versions %}
<option{% if sv.name == schema_current_version %} selected="selected"{% endif %}>{{ sv.name }}</option>
{% if tags %}
<optgroup label="Tags">
{% for tag in tags %}
<option{% if tag.name == schema_current_version %} selected{% endif %}>{{ tag.name }}</option>
{% endfor %}
</optgroup>
{% endif %}
{% if branches %}
<optgroup label="Branches">
{% for branch in branches %}
<option{% if branch.name == schema_current_version %} selected{% endif %}>{{ branch.name }}</option>
{% endfor %}
</optgroup>
{% endif %}
</select>
</div>
</form>
......
......@@ -9,7 +9,7 @@
<div class="col-lg-6 mb-4">
<div class="card">
<div class="card-body">
{{ schema_info_macros.html(schema_info, schema_versions, schema_current_version, doc_url) }}
{{ schema_info_macros.html(schema_info, branches, tags, schema_current_version, doc_url) }}
</div>
</div>
</div>
......@@ -87,7 +87,7 @@
{% endblock %}
{% block page_scripts %}
{% if schema_versions %}
{% if branches or tags %}
{{ schema_info_macros.script() }}
{% endif %}
{% endblock %}
\ No newline at end of file
......@@ -42,7 +42,7 @@
<div class="col-lg-6 mb-4">
<div class="card">
<div class="card-body">
{{ schema_info_macros.html(schema_info, None, schema_current_version, doc_url) }}
{{ schema_info_macros.html(schema_info, None, None, schema_current_version, doc_url) }}
</div>
</div>
</div>
......
This diff is collapsed.
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