Commit 128689fe authored by Pierre Dittgen's avatar Pierre Dittgen

Display documentation link for master branch

parent 65b02f92
Pipeline #1017 failed with stage
in 16 seconds
{% macro html(schema_info, schema_versions, schema_current_version) %} {% macro html(schema_info, schema_versions, schema_current_version, doc_url) %}
<h5 class="card-title"> <h5 class="card-title">
Schéma Schéma
{% if schema_info.title %} {% if schema_info.title %}
...@@ -26,14 +26,17 @@ ...@@ -26,14 +26,17 @@
</ul> </ul>
</p> </p>
{% endif %} {% endif %}
{% if schema_info.doc_url or schema_info.url %} {% if schema_info.homepage or schema_info.url %}
<p> <p>
{% if schema_info.doc_url %} {% if schema_info.homepage %}
<a href="{{ schema_info.doc_url }}" target="_blank" class="card-link">Documentation</a> Site : <a href="{{ schema_info.homepage }}" target="_blank" title="{{ schema_info.homepage }}" class="card-link">{{ schema_info.homepage | truncate(40) }}</a>
{% endif %} {% endif %}
{#
{% if schema_info.homepage and schema_info.url %}<br />{% endif %}
{% if schema_info.url %} {% if schema_info.url %}
Source : <a href="{{ schema_info.url }}" target="_blank" title="{{ schema_info.url }}" class="card-link">{{ schema_info.url | truncate(40) }}</a> Source : <a href="{{ schema_info.url }}" target="_blank" title="{{ schema_info.url }}" class="card-link">{{ schema_info.url | truncate(40) }}</a>
{% endif %} {% endif %}
#}
</p> </p>
{% endif %} {% endif %}
{% if schema_versions %} {% if schema_versions %}
...@@ -44,6 +47,10 @@ ...@@ -44,6 +47,10 @@
<option{% if sv == schema_current_version %} selected="selected"{% endif %}>{{ sv }}</option> <option{% if sv == schema_current_version %} selected="selected"{% endif %}>{{ sv }}</option>
{% endfor %} {% endfor %}
</select> </select>
{% if schema_current_version == 'master' %}
<br />
<a href="{{ doc_url }}" target="_blank">Documentation</a>
{% endif %}
</p> </p>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<div class="col-md-4 {{ cols_my_classes }}"> <div class="col-md-4 {{ cols_my_classes }}">
<div class="card bg-faded"> <div class="card bg-faded">
<div class="card-body"> <div class="card-body">
{{ schema_info_part.html(schema_info, schema_versions, schema_current_version) }} {{ schema_info_part.html(schema_info, schema_versions, schema_current_version, doc_url) }}
</div> </div>
</div> </div>
</div> </div>
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<div class="col-md-{% if print_mode %}12{% else %}5{% endif %} my-4"> <div class="col-md-{% if print_mode %}12{% else %}5{% endif %} my-4">
<div class="card bg-faded"> <div class="card bg-faded">
<div class="card-body"> <div class="card-body">
{{ schema_info_part.html(schema_info, schema_versions, schema_current_version) }} {{ schema_info_part.html(schema_info, schema_versions, schema_current_version, doc_url) }}
<hr /> <hr />
<div> <div>
<h5 class="card-title"> <h5 class="card-title">
......
...@@ -34,7 +34,7 @@ log = logging.getLogger(__name__) ...@@ -34,7 +34,7 @@ log = logging.getLogger(__name__)
class SchemaInstance(): class SchemaInstance():
"""Handly class to handle schema information""" """Handly class to handle schema information"""
def __init__(self, url=None, name=None, ref=None, spec=None, versions=None): def __init__(self, url=None, name=None, ref=None, spec=None, versions=None, doc_url=None):
"""This function is not intended to be called directly """This function is not intended to be called directly
but via from_parameters() static method!""" but via from_parameters() static method!"""
self.url = url self.url = url
...@@ -42,12 +42,13 @@ class SchemaInstance(): ...@@ -42,12 +42,13 @@ class SchemaInstance():
self.ref = ref self.ref = ref
self.spec = spec self.spec = spec
self.versions = versions self.versions = versions
self.doc_url = doc_url
@staticmethod @staticmethod
def from_parameters(parameter_dict, schema_catalog_map): def from_parameters(parameter_dict, schema_catalog_map):
"""Initializes schema instance from requests dict and tableschema catalog (for name ref) """Initializes schema instance from requests dict and tableschema catalog (for name ref)
""" """
schema_url, schema_name, schema_ref, versions = None, None, None, None schema_url, schema_name, schema_ref, versions, doc_url = None, None, None, None, None
# From schema_url # From schema_url
if 'schema_url' in parameter_dict: if 'schema_url' in parameter_dict:
...@@ -78,6 +79,7 @@ class SchemaInstance(): ...@@ -78,6 +79,7 @@ class SchemaInstance():
# Git refs # Git refs
if table_schema_reference: if table_schema_reference:
versions = table_schema_reference.get_refs() versions = table_schema_reference.get_refs()
doc_url = table_schema_reference.doc_url
options = {'ref': schema_ref} if schema_ref else {} options = {'ref': schema_ref} if schema_ref else {}
schema_url = table_schema_reference.get_schema_url(**options) schema_url = table_schema_reference.get_schema_url(**options)
...@@ -85,7 +87,8 @@ class SchemaInstance(): ...@@ -85,7 +87,8 @@ class SchemaInstance():
else: else:
return None return None
return SchemaInstance(schema_url, schema_name, schema_ref, schema_from_url(schema_url), versions) return SchemaInstance(url=schema_url, name=schema_name, ref=schema_ref,
spec=schema_from_url(schema_url), versions=versions, doc_url=doc_url)
def request_parameters(self): def request_parameters(self):
if self.name: if self.name:
...@@ -384,6 +387,7 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource): ...@@ -384,6 +387,7 @@ def validate(schema_instance: SchemaInstance, source: ValidataResource):
validation_date=report_datetime.strftime('le %d/%m/%Y à %Hh%M'), validation_date=report_datetime.strftime('le %d/%m/%Y à %Hh%M'),
source=source, source_data=source_data, source=source, source_data=source_data,
schema_current_version=schema_instance.ref, schema_current_version=schema_instance.ref,
doc_url = schema_instance.doc_url,
print_mode=request.args.get('print', 'false') == 'true', print_mode=request.args.get('print', 'false') == 'true',
badge_url=badge_url, badge_msg=badge_msg, badge_url=badge_url, badge_msg=badge_msg,
report_str=json.dumps(validata_report, sort_keys=True, indent=2), report_str=json.dumps(validata_report, sort_keys=True, indent=2),
...@@ -542,6 +546,7 @@ def custom_validator(): ...@@ -542,6 +546,7 @@ def custom_validator():
return render_template('validation_form.html', title=title, return render_template('validation_form.html', title=title,
schema_info=schema_info, schema_versions=schema_versions, schema_info=schema_info, schema_versions=schema_versions,
schema_current_version=schema_instance.ref, schema_current_version=schema_instance.ref,
doc_url = schema_instance.doc_url,
schema_params=schema_instance.request_parameters(), schema_params=schema_instance.request_parameters(),
breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'}, ]) breadcrumbs=[{'url': url_for('home'), 'title': 'Accueil'}, ])
......
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