Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Validata
Validata UI
Commits
6be6987b
Commit
6be6987b
authored
Jun 19, 2019
by
Pierre Dittgen
Browse files
Rework badge generation
parent
fee5452d
Pipeline
#1039
failed with stage
in 21 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.env.example
View file @
6be6987b
...
...
@@ -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
t
w
o
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
...
...
validata_ui/config.py
View file @
6be6987b
...
...
@@ -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
+=
'/'
...
...
validata_ui/templates/validation_report.html
View file @
6be6987b
...
...
@@ -31,7 +31,9 @@
{% endif %}
<h1
class=
"my-4"
>
{{ title }}
</h1>
<p>
Validation effectuée {{ validation_date }}
</p>
{% if display_badge %}
<p><img
src=
"{{ badge_url }}"
alt=
"{{ badge_msg }}"
title=
"{{ badge_msg }}"
/></p>
{% endif %}
{% if print_mode %}
</div>
<div
class=
"col-md-7"
>
...
...
validata_ui/views.py
View file @
6be6987b
...
...
@@ -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
,
s
pec
=
None
,
versions
=
None
,
doc_url
=
None
):
def
__init__
(
self
,
url
=
None
,
name
=
None
,
ref
=
None
,
s
chema
=
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
.
s
pec
=
spec
self
.
s
chema
=
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
,
s
pec
=
schema_from_url
(
schema_url
),
versions
=
versions
,
doc_url
=
doc_url
)
s
chema
=
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
.
s
pec
)
validata_report
=
create_validata_ui_report
(
validata_core_report
,
schema_instance
.
s
chema
.
descriptor
)
# Display report to the user
validator_form_url
=
compute_validation_form_url
(
schema_instance
)
schema_info
,
validator_title
=
compute_schema_info
(
schema_instance
.
s
pec
,
schema_instance
.
url
)
schema_info
,
validator_title
=
compute_schema_info
(
schema_instance
.
s
chema
,
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
.
s
pec
,
schema_instance
.
url
)
schema_info
,
title
=
compute_schema_info
(
schema_instance
.
s
chema
,
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
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment