Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Validata
validata-ui
Commits
848d5bae
Commit
848d5bae
authored
Jun 27, 2019
by
Christophe Benz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix homepage sections generation, use schema_reference name
parent
34204acc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
38 deletions
+37
-38
validata_ui/__init__.py
validata_ui/__init__.py
+9
-9
validata_ui/templates/home.html
validata_ui/templates/home.html
+4
-4
validata_ui/views.py
validata_ui/views.py
+24
-25
No files found.
validata_ui/__init__.py
View file @
848d5bae
...
...
@@ -43,15 +43,15 @@ class SchemaCatalogRegistry:
self
.
ref_map
[
name
]
=
ref
def
build_schema_catalog
(
self
,
name
):
if
name
in
self
.
ref_map
:
ref
=
self
.
ref_map
[
name
]
try
:
catalog
=
opendataschema
.
SchemaCatalog
(
ref
,
session
=
self
.
session
)
except
requests
.
exceptions
.
RequestException
as
exc
:
log
.
e
xception
(
exc
)
return
None
return
catalog
return
None
ref
=
self
.
ref_map
.
get
(
name
)
if
not
ref
:
return
None
try
:
catalog
=
opendataschema
.
SchemaCatalog
(
ref
,
session
=
self
.
session
)
except
requests
.
exceptions
.
RequestE
xception
as
exc
:
log
.
exception
(
exc
)
return
None
return
catalog
caching_session
=
cachecontrol
.
CacheControl
(
requests
.
Session
())
...
...
validata_ui/templates/home.html
View file @
848d5bae
...
...
@@ -4,17 +4,17 @@
{% block content %}
<div
class=
"container"
>
{% for section in
config.
sections %}
{% for section in sections %}
{% if section.catalog %}
<div
class=
"mb-5"
>
<h2
class=
"my-4"
>
{{section.title}}
</h2>
<h2
class=
"my-4"
>
{{
section.title
}}
</h2>
<form
action=
"{{ url_for('custom_validator') }}"
method=
"GET"
>
<div
class=
"form-row"
>
<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 item in section.catalog | sort(attribute='title') %}
<option
value=
"{{ item.name }}"
>
{{ item.title }}
</option>
<option
value=
"{{
section.name }}.{{
item.name }}"
>
{{ item.title }}
</option>
{% endfor %}
</select>
</div>
...
...
@@ -53,7 +53,7 @@
</form>
</div>
{% for section in
config.
sections %}
{% for section in sections %}
{% if section.links %}
<div
class=
"my-5"
>
<h2
class=
"my-4"
>
{{ section.title }}
</h2>
...
...
validata_ui/views.py
View file @
848d5bae
...
...
@@ -425,37 +425,36 @@ def bytes_data(f):
return
iob
.
getvalue
()
def
homepage_config_with_schema_metadata
(
ui_config
):
"""Replace catalog url within ui_config by schema references
containing schema metadata properties"""
extended_ui_config
=
ui_config
.
copy
()
for
section
in
extended_ui_config
[
'sections'
]:
section_name
=
section
[
'name'
]
schema_catalog
=
get_schema_catalog
(
section_name
)
if
schema_catalog
is
None
:
section
[
'catalog'
]
=
[]
continue
schema_list
=
[]
for
ref
in
schema_catalog
.
references
:
# Loads default table schema for each schema reference
table_schema
=
tableschema_from_url
(
ref
.
get_schema_url
())
schema_list
.
append
({
'name'
:
'{}.{}'
.
format
(
section_name
,
ref
.
name
),
# Extracts title, description, ...
**
extract_schema_metadata
(
table_schema
)
})
section
[
'catalog'
]
=
schema_list
return
extended_ui_config
# Routes
@
app
.
route
(
'/'
)
def
home
():
""" Home page """
home_config
=
homepage_config_with_schema_metadata
(
config
.
HOMEPAGE_CONFIG
)
return
render_template
(
'home.html'
,
config
=
home_config
)
def
iter_sections
():
"""Yield sections of the home page, filled with schema metadata."""
if
not
config
.
HOMEPAGE_CONFIG
:
return
for
section
in
config
.
HOMEPAGE_CONFIG
[
'sections'
]:
home_section
=
{
"name"
:
section
[
'name'
],
"title"
:
section
[
"title"
]}
if
"catalog"
in
section
:
schema_catalog
=
get_schema_catalog
(
section
[
'name'
])
if
schema_catalog
:
home_section_catalog
=
[]
for
schema_reference
in
schema_catalog
.
references
:
# Loads default table schema for each schema reference
table_schema
=
tableschema_from_url
(
schema_reference
.
get_schema_url
())
home_section_catalog
.
append
({
"name"
:
schema_reference
.
name
,
"title"
:
table_schema
.
descriptor
.
get
(
"title"
)
or
schema_reference
.
name
})
home_section
[
'catalog'
]
=
home_section_catalog
if
"links"
in
section
:
home_section
[
"links"
]
=
section
[
"links"
]
yield
home_section
return
render_template
(
'home.html'
,
sections
=
list
(
iter_sections
()))
@
app
.
route
(
'/pdf'
)
...
...
Write
Preview
Markdown
is supported
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