Commit e68dc2bf authored by Yohan Boniface's avatar Yohan Boniface

Explorer: add a raw catalog XML viewer

parent 4b55ed65
......@@ -9,6 +9,7 @@ from .config import RAW_RULES, SCHEMA, GLOSSARY
from .core import simulate
from .debugging import data_from_lbf_url, make_feature
from .openapis import OPENAPI
from .routine import get_formation_xml
logger = logging.getLogger('trefle')
logger.setLevel(logging.DEBUG)
......@@ -81,6 +82,12 @@ async def explore_glossary(request, response):
response.json = GLOSSARY
@app.route('/explore/catalog')
async def explore_catalog(request, response):
response.body = await get_formation_xml(request.query.get('id'))
response.headers['Content-Type'] = 'text/xml'
@app.route('/explore/decode-lbf-url')
async def decode_lbf_url(request, response):
response.json = data_from_lbf_url(request.query.get('url'))
......@@ -98,7 +98,15 @@ a {
grid-template-columns: 1fr 2fr;
}
main {
padding: 10px;
padding: 1rem;
}
pre {
padding: 5px;
border: solid 1px #68c3a3;
background-color: #eee;
max-width: 1200px;
font-family: 'mono';
white-space: pre-wrap;
}
......
<catalog>
<section>
<h2>Catalogue</h2>
<form onsubmit={ this.submit }>
<input type="text" ref="intercarif" placeholder="Identifiant INTERCARIF" name="intercarif">
<input type="submit" value="Chercher">
</form>
</section>
<section class=results if={ this.refs.intercarif.value }>
<h2>Formation</h2>
<pre if={ this.xml }>{ this.xml }</pre>
<p if={ this.refs.intercarif.value && !this.xml }>Aucune formation trouvée avec l'identifiant «{ this.refs.intercarif.value }».</p>
</section>
<script>
this.results = []
this.get = (id) => {
fetch(`/explore/catalog?id=${id}`)
.then((response) => response.text())
.then((data) => {
this.xml = data
this.update()
})
}
this.submit = (e) => {
e.preventDefault();
const id = this.refs.intercarif.value
if (!id) return
this.get(id)
}
</script>
</catalog>
......@@ -34,20 +34,4 @@
</script>
<style scoped>
:scope {
display: grid;
grid-template-columns: 2fr 4fr;
grid-gap: 10px;
overflow: hidden;
}
h2 {
font-variant: small-caps;
}
.results {
padding: 10px;
border-left: 1px solid #ddd;
}
</style>
</idcc-search>
<rule>
<pre ref=pre></pre>
<style scoped>
pre {
padding: 5px;
border: solid 1px #68c3a3;
background-color: #eee;
max-width: 1200px;
font-family: 'mono';
white-space: pre-wrap;
}
pre strong {
font-family: 'mono';
font-weight: bold;
......
<tools>
<idcc-search class=tools></idcc-search>
<catalog class=tools></catalog>
<script>
this.mixin(View)
</script>
<style scoped>
.tools {
margin-bottom: 1rem;
padding-bottom: 2rem;
border-bottom: 1px solid #eee;
}
h2 {
font-variant: small-caps;
}
......
......@@ -13,6 +13,7 @@
<script src="components/simulate.tag.html" type="riot/tag"></script>
<script src="components/tools.tag.html" type="riot/tag"></script>
<script src="components/idcc-search.tag.html" type="riot/tag"></script>
<script src="components/catalog.tag.html" type="riot/tag"></script>
<header data-is=navbar></header>
<main>
......
......@@ -78,15 +78,19 @@ def check_eligibilite(context):
Rule.process(ELIGIBILITE, context)
async def get_formation_xml(formation_id):
return (await http_get(f'{INTERCARIF_URL}?num={formation_id}')).content
async def populate_formation(context):
if not context.get('formation.numero'):
return
formation_id = context['formation.numero']
response = await http_get(f'{INTERCARIF_URL}?num={formation_id}')
xml = await get_formation_xml(formation_id)
try:
await populate_formation_from_bytes(context, response.content)
await populate_formation_from_bytes(context, xml)
except ValueError as err:
# Give more context.
err.args = (f'Error with id `{formation_id}`: `{err}`',)
......
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