From 52a06822b273d2d35d9b630c889435fed80d2b0f Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Wed, 30 Mar 2022 17:27:59 +0200 Subject: Ask for reference when partitioning several clients Allow the user to choose a computer as reference to display the partition scheme form. --- ogcp/forms/action_forms.py | 6 +++++ ogcp/templates/actions/select_client.html | 26 +++++++++++++++++++ ogcp/templates/commands.html | 2 +- ogcp/views.py | 43 ++++++++++++++++++++++++++----- 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 ogcp/templates/actions/select_client.html (limited to 'ogcp') diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index a2cac37..5e8bce1 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -58,6 +58,12 @@ class PartitionForm(FlaskForm): size = IntegerField(label=_l('Size (KB)')) format_partition = BooleanField(label=_l('Format')) +class SelectClientForm(FlaskForm): + ips = HiddenField() + selected_client = SelectField(label=_l('Select one client as reference to ' + 'define the partition scheme')) + ok = SubmitField(label=_l('Ok')) + class SetupForm(FlaskForm): ips = HiddenField() disk = HiddenField() diff --git a/ogcp/templates/actions/select_client.html b/ogcp/templates/actions/select_client.html new file mode 100644 index 0000000..ca8fff2 --- /dev/null +++ b/ogcp/templates/actions/select_client.html @@ -0,0 +1,26 @@ +{% extends 'commands.html' %} +{% import 'bootstrap/wtf.html' as wtf %} +{% import 'macros.html' as macros %} + +{% set sidebar_state = 'disabled' %} +{% set btn_back = true %} + +{% block nav_image %} active{% endblock %} +{% block nav_image_restore %} active{% endblock %} +{% block content %} + +{% set ip_list = form.ips.data.split(' ') %} +{% set ip_count = ip_list | length %} +

+ {{ _('Partitioning %(ip_count)d client(s)', ip_count=ip_count) }} +

+ +{{ macros.cmd_selected_clients(selected_clients) }} + +{{ wtf.quick_form(form, + action=url_for('action_setup_show'), + method='get', + button_map={'restore': 'primary'}, + extra_classes='m-5') }} + +{% endblock %} diff --git a/ogcp/templates/commands.html b/ogcp/templates/commands.html index 76dc191..65ab840 100644 --- a/ogcp/templates/commands.html +++ b/ogcp/templates/commands.html @@ -41,7 +41,7 @@ + form="scopesForm" formaction="{{ url_for('action_setup_select') }}" formmethod="get"> diff --git a/ogcp/views.py b/ogcp/views.py index 802b4bc..c3c1fef 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -12,7 +12,7 @@ from ogcp.forms.action_forms import ( WOLForm, SetupForm, ClientDetailsForm, ImageDetailsForm, HardwareForm, SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm, RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm, - GenericForm + GenericForm, SelectClientForm ) from flask_login import ( current_user, LoginManager, @@ -335,6 +335,32 @@ def action_wol(): else: return redirect(url_for('commands')) + +@app.route('/action/setup/select', methods=['GET']) +@login_required +def action_setup_select(): + args = request.args.copy() + + ips = parse_elements(args.to_dict()) + if not validate_elements(ips): + return redirect(url_for('commands')) + + if len(ips) == 1: + ip = list(ips)[0] + return redirect(url_for('action_setup_show', ip=ip)) + + form = SelectClientForm() + form.ips.data = " ".join(ips) + form.selected_client.choices = list(ips) + + scopes, _ = get_scopes(ips) + selected_clients = list(get_selected_clients(scopes['scope']).items()) + + return render_template('actions/select_client.html', + selected_clients=selected_clients, + form=form, scopes=scopes) + + @app.route('/action/setup', methods=['GET']) @login_required def action_setup_show(): @@ -343,12 +369,15 @@ def action_setup_show(): default_disk = 1 selected_disk = int(args.pop('disk', default_disk)) - ips = parse_elements(args.to_dict()) - if not validate_elements(ips): - return redirect(url_for('commands')) + if args.get('ip'): + ips = {args['ip']} + ips_str = base_client = args['ip'] + else: + ips_str = args['ips'] + ips = set(args['ips'].split(' ')) + base_client = args['selected_client'] - ip = list(ips)[0] - db_partitions = get_client_setup(ip) + db_partitions = get_client_setup(base_client) filtered_partitions = [p for p in db_partitions if p.get('disk') == selected_disk] @@ -357,7 +386,7 @@ def action_setup_show(): if d.get('partition') == disk_partition] form = SetupForm() - form.ips.data = " ".join(ips) + form.ips.data = ips_str form.disk.data = selected_disk # If partition table is empty, set MSDOS form.disk_type.data = filtered_partitions[0]['code'] or 1 -- cgit v1.2.3-18-g5258