diff --git a/render/__main__.py b/render/__main__.py index 887c01c..8c7fd79 100644 --- a/render/__main__.py +++ b/render/__main__.py @@ -6,22 +6,24 @@ Usage: `python -m render` from traceback import format_exc from flask import Flask, render_template, request -from glicid_spawner.form import TEMPLATE_FORM, options_from_form +from glicid_spawner.form import TEMPLATES, options_from_form from glicid_spawner.micromamba import MicromambaEnv from glicid_spawner.resources import CPU, GPU, RAM from livereload import Server -# Monkeypatch +# Dummy username and python environments +USERNAME = 'john-doe' +ENVS = [ + MicromambaEnv('USER', 'foo', f'/{USERNAME}/envs/foo'), + MicromambaEnv('USER', 'bar', f'/{USERNAME}/envs/bar'), + MicromambaEnv('GLOBAL', 'baz', '/global/envs/baz'), +] 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, + 'username': USERNAME, + 'envs': ENVS, + 'cpus': CPU, + 'rams': RAM, + 'gpus': GPU, } @@ -34,7 +36,9 @@ app.debug = True def home(): """Form spawner home page.""" return render_template( - 'form.html', spawner_options_form=TEMPLATE_FORM.render(**OPTIONS), options=OPTIONS + 'form.html', + spawner_options_form=TEMPLATES.get_template('spawner_form.jinja').render(**OPTIONS), + options=OPTIONS, ) diff --git a/src/glicid_spawner/form.py b/src/glicid_spawner/form.py index 15665b7..300de95 100644 --- a/src/glicid_spawner/form.py +++ b/src/glicid_spawner/form.py @@ -9,23 +9,23 @@ TEMPLATES = Environment( loader=PackageLoader('glicid_spawner'), autoescape=select_autoescape(), ) -TEMPLATE_FORM = TEMPLATES.get_template('spawner_form.html') def options_attrs(username: str) -> dict: """Form options attributes.""" return { 'username': username, - 'python_envs': get_envs(username), - 'cpu_available': CPU, - 'ram_available': RAM, - 'gpu_available': GPU, + 'envs': get_envs(username), + 'cpus': CPU, + 'rams': RAM, + 'gpus': GPU, } def options_form(username: str) -> str: """Render default spawner form.""" - return TEMPLATE_FORM.render(**options_attrs(username)) + template = TEMPLATES.get_template('spawner_form.jinja') + return template.render(**options_attrs(username)) def options_from_form(formdata) -> dict: diff --git a/src/glicid_spawner/templates/spawner_form.jinja b/src/glicid_spawner/templates/spawner_form.jinja new file mode 100644 index 0000000..d6263f2 --- /dev/null +++ b/src/glicid_spawner/templates/spawner_form.jinja @@ -0,0 +1,12 @@ + + +
+ + {% include "views/username.jinja" %} + {% include "views/envs.jinja" %} + {% include "views/resources.jinja" %} + {% include "views/slurm.jinja" %} + +
diff --git a/src/glicid_spawner/templates/static/style.css b/src/glicid_spawner/templates/static/style.css new file mode 100644 index 0000000..01bdc34 --- /dev/null +++ b/src/glicid_spawner/templates/static/style.css @@ -0,0 +1,24 @@ +/* Spawner form addition style */ +input[type=radio] { + display: none; +} + +input[type=radio]:checked+label { + background-color: #f37524; + border-color: #e34f21; + color: #fff; +} + +.panel-heading .panel-title-toggle { + text-decoration: none; +} + +.panel-heading .panel-title-toggle:before { + font-family: 'FontAwesome'; + content: "\\f078"; + color: lightgrey; +} + +.panel-heading .panel-title-toggle.collapsed:before { + content: "\\f054"; +} diff --git a/src/glicid_spawner/templates/views/envs.jinja b/src/glicid_spawner/templates/views/envs.jinja new file mode 100644 index 0000000..954db74 --- /dev/null +++ b/src/glicid_spawner/templates/views/envs.jinja @@ -0,0 +1,10 @@ +
+ +
+ +
+
diff --git a/src/glicid_spawner/templates/spawner_form.html b/src/glicid_spawner/templates/views/resources.jinja similarity index 60% rename from src/glicid_spawner/templates/spawner_form.html rename to src/glicid_spawner/templates/views/resources.jinja index 25ebf10..1d8382a 100644 --- a/src/glicid_spawner/templates/spawner_form.html +++ b/src/glicid_spawner/templates/views/resources.jinja @@ -1,24 +1,9 @@ -
-
- -
-
{{ username }}
-
-
-
- -
- -
-
+
+
- {%- for cpu in cpu_available -%} + {%- for cpu in cpus -%}
@@ -29,10 +14,11 @@ {% endfor -%}
+
- {%- for ram in ram_available -%} + {%- for ram in rams -%}
@@ -43,10 +29,11 @@ {% endfor -%}
+
- {%- for gpu in gpu_available -%} + {%- for gpu in gpus -%}
@@ -57,32 +44,20 @@ {% endfor -%}
-
- -
-
24 h
-
+
+ +
+ +
+
24 h