summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-09-03 14:51:15 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2021-09-03 14:51:15 +0200
commitda9b2ea9c2ef37eb191ba0a9e78e62ce942dc912 (patch)
tree6e54487fc3ab2fb028402c8d84c06efe82caccc9
parentd83e456daf20e070a3eee51d885166566177c369 (diff)
Add image details action
This action is used to visualize the specific details of an image, as its ID, name, size, etc.
-rw-r--r--ogcp/forms/action_forms.py11
-rw-r--r--ogcp/templates/actions/image_details.html13
-rw-r--r--ogcp/templates/images.html2
-rw-r--r--ogcp/views.py26
4 files changed, 50 insertions, 2 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index 1722d8b..d881065 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -7,7 +7,7 @@
from wtforms import (
Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField,
- StringField, RadioField, FormField, FieldList
+ StringField, RadioField, FormField, FieldList, DecimalField
)
from wtforms.validators import InputRequired
from flask_wtf import FlaskForm
@@ -143,3 +143,12 @@ class DeleteRoomForm(FlaskForm):
room = SelectField(label=_('Room'),
validators=[InputRequired()])
submit = SubmitField(label=_('Submit'))
+
+class ImageDetailsForm(FlaskForm):
+ id = StringField(label=_('Id'))
+ name = StringField(label=_('Name'))
+ size = DecimalField(label=_('Size (GiB)'))
+ datasize = DecimalField(label=_('Datasize (GiB)'))
+ modified = StringField(label=_('Modified'))
+ permissions = StringField(label=_('Permissions'))
+ software_id = StringField(label=_('Software id'))
diff --git a/ogcp/templates/actions/image_details.html b/ogcp/templates/actions/image_details.html
new file mode 100644
index 0000000..a4feb55
--- /dev/null
+++ b/ogcp/templates/actions/image_details.html
@@ -0,0 +1,13 @@
+{% extends 'base.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% block content %}
+
+<h1 class="m-5">{{_('Image details')}}</h1>
+
+{{ wtf.quick_form(form,
+ method='post',
+ button_map={'create': 'primary'},
+ extra_classes="mx-5") }}
+
+{% endblock %}
diff --git a/ogcp/templates/images.html b/ogcp/templates/images.html
index e698af9..3faa029 100644
--- a/ogcp/templates/images.html
+++ b/ogcp/templates/images.html
@@ -25,5 +25,7 @@
{% endblock %}
{% block commands %}
+ <input class="btn btn-light" type="submit" value="{{ _('Image details') }}"
+ form="imagesForm" formaction="{{ url_for('action_image_info') }}" formmethod="get">
{% endblock %}
diff --git a/ogcp/views.py b/ogcp/views.py
index 3e80120..11e3693 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -9,7 +9,7 @@ from flask import (
g, render_template, url_for, flash, redirect, request, jsonify, make_response
)
from ogcp.forms.action_forms import (
- WOLForm, SetupForm, ClientDetailsForm, HardwareForm,
+ WOLForm, SetupForm, ClientDetailsForm, ImageDetailsForm, HardwareForm,
SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm,
RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm
)
@@ -774,3 +774,27 @@ def images():
r = g.server.get('/images')
images = r.json()['images']
return render_template('images.html', images=images)
+
+@app.route('/action/image/info', methods=['GET'])
+@login_required
+def action_image_info():
+ form = ImageDetailsForm()
+ ids = parse_elements(request.args.to_dict())
+ if not validate_elements(ids, max_len=1):
+ return redirect(url_for('images'))
+
+ id = ids.pop()
+ r = g.server.get('/images')
+ images = r.json()['images']
+ image = next(img for img in images if img['id'] == int(id))
+
+ form.id.data = image['id']
+ form.name.data = image['name']
+ # Bytes to Gibibytes
+ form.size.data = image['size'] / 1024 ** 3
+ form.datasize.data = image['datasize'] / 1024 ** 3
+ form.modified.data = image['modified']
+ form.permissions.data = image['permissions']
+ form.software_id.data = image['software_id']
+
+ return render_template('actions/image_details.html', form=form)