diff options
author | Daniel GarcĂa Moreno <danigm@soleta.eu> | 2021-06-30 12:40:22 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-06-30 17:19:55 +0200 |
commit | 42dc44323e4cf0eaf0b563ba02f368942cf86e3d (patch) | |
tree | 807a055b475f7358317239017b38872294a39491 /ogcp/views.py | |
parent | 288654722d061591ac834ecf9fb2310280473323 (diff) |
Add new partition button in setup action
This patch adds a way to add a new partition to the setup.html template.
This button opens a modal dialog with a new form and calls a new
endpoint to create the new partition (this endpoint does nothing, it's
needed to be implemented in the future).
I've followed the initial design for this template, with one form per
each partition, so every button will call a function and reload the
page.
It's possible to do all actions at once, but that will require a rework
of this, to do that we can just define an unique form in the whole html,
remove all the "Modify" buttons and add just one "Apply" button at the
end. But maybe that option is a lot complex in the backend because will
require to validate all the changes at once.
This patch also improves the setup.html form without using
flask-bootstrap and rendering the form in the template directly with the
bootstrap4 classes.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index c4b8afe..0505f66 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -9,9 +9,9 @@ from flask import ( g, render_template, url_for, flash, redirect, request, jsonify, make_response ) from ogcp.forms.action_forms import ( - WOLForm, PartitionForm, ClientDetailsForm, HardwareForm, SessionForm, - ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm, RoomForm, - DeleteRoomForm + WOLForm, PartitionForm, NewPartitionForm, ClientDetailsForm, HardwareForm, + SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm, + RoomForm, DeleteRoomForm ) from flask_login import ( current_user, LoginManager, @@ -226,12 +226,19 @@ def action_wol(): @app.route('/action/setup', methods=['GET']) @login_required -def action_setup_show(): - ips = parse_ips(request.args.to_dict()) +def action_setup_show(ips=None, new_partition_form=None): + if not ips: + ips = parse_ips(request.args.to_dict()) + db_partitions = get_client_setup(ips) forms = [PartitionForm() for _ in db_partitions] forms = list(forms) + if not new_partition_form: + new_partition_form = NewPartitionForm() + new_partition_form.ips.data = " ".join(ips) + new_partition_form.create.render_kw = {"formaction": url_for('action_setup_create')} + for form, db_part in zip(forms, db_partitions): form.ips.data = " ".join(ips) form.disk.data = db_part['disk'] @@ -249,8 +256,25 @@ def action_setup_show(): scopes, _clients = get_scopes(ips) return render_template('actions/setup.html', forms=forms, + new_partition_form=new_partition_form, scopes=scopes) +@app.route('/action/setup/create', methods=['POST']) +@login_required +def action_setup_create(): + form = NewPartitionForm(request.form) + ips = form.ips.data.split(' ') + + if form.validate(): + # TODO: create the real partition + flash(_('Partition created successfully'), category='info') + return redirect(url_for('action_setup_show', ips=ips)) + + flash(_('Invalid partition configuration'), category='error') + # This return will maintain the new partition form state, but will break + # the F5 behavior in the browser + return action_setup_show(ips, form) + @app.route('/action/setup/modify', methods=['POST']) @login_required def action_setup_modify(): |