Add pretty print to options rendering
This commit is contained in:
parent
397b54cdbe
commit
867e217d44
2 changed files with 19 additions and 13 deletions
|
@ -3,21 +3,27 @@
|
|||
Usage: `python -m render`
|
||||
|
||||
"""
|
||||
from pathlib import Path
|
||||
from traceback import format_exc
|
||||
|
||||
import glicid_spawner
|
||||
from flask import Flask, render_template, request
|
||||
from glicid_spawner.form import options_attrs, options_form, options_from_form
|
||||
from glicid_spawner.form import TEMPLATE_FORM, options_from_form
|
||||
from glicid_spawner.micromamba import MicromambaEnv
|
||||
from glicid_spawner.resources import CPU, GPU, RAM
|
||||
from livereload import Server
|
||||
|
||||
# Monkeypatch
|
||||
USERNAME = 'john-doe'
|
||||
glicid_spawner.micromamba.MICROMAMBA_ROOT = (
|
||||
Path(__file__).parent / '..' / 'tests' / 'data' / 'micromamba'
|
||||
).resolve()
|
||||
glicid_spawner.micromamba.GLOBAL_USER = 'global'
|
||||
glicid_spawner.micromamba.GLOBAL_EXCLUDED = 'qux'
|
||||
OPTIONS = {
|
||||
'username': 'john-doe',
|
||||
'python_envs': [
|
||||
MicromambaEnv('USER', 'foo', '/john-doe/envs/foo'),
|
||||
MicromambaEnv('USER', 'bar', '/john-doe/envs/bar'),
|
||||
MicromambaEnv('GLOBAL', 'baz', '/global/envs/baz'),
|
||||
],
|
||||
'cpu_available': CPU,
|
||||
'ram_available': RAM,
|
||||
'gpu_available': GPU,
|
||||
}
|
||||
|
||||
|
||||
# Flask app
|
||||
app = Flask(__name__)
|
||||
|
@ -28,7 +34,7 @@ app.debug = True
|
|||
def home():
|
||||
"""Form spawner home page."""
|
||||
return render_template(
|
||||
'form.html', spawner_options_form=options_form(USERNAME), options=options_attrs(USERNAME)
|
||||
'form.html', spawner_options_form=TEMPLATE_FORM.render(**OPTIONS), options=OPTIONS
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
<div class="row col-sm-offset-2 col-sm-8">
|
||||
<h3>📝 Submitted form data</h3>
|
||||
<pre><code>{{formdata}}</code></pre>
|
||||
<pre><code>{{formdata|pprint}}</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="row col-sm-offset-2 col-sm-8 text-success">
|
||||
{% if options %}
|
||||
<h3>✅ Parsed spawner options</h3>
|
||||
<pre><code>{{options}}</code></pre>
|
||||
<pre><code>{{options|pprint}}</code></pre>
|
||||
{% else %}
|
||||
<h3>⛔️ Spawner options error</h3>
|
||||
<pre><code>{{err}}</code></pre>
|
||||
<pre><code>{{err|pprint}}</code></pre>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue