summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-03-30 17:27:59 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-04-01 15:07:05 +0200
commit52a06822b273d2d35d9b630c889435fed80d2b0f (patch)
treeec1df84be2713b684cff1b838b97313684329349
parentbb39f67a46fc4f39fc78e6191d0600d854d7075f (diff)
Ask for reference when partitioning several clients
Allow the user to choose a computer as reference to display the partition scheme form.
-rw-r--r--ogcp/forms/action_forms.py6
-rw-r--r--ogcp/templates/actions/select_client.html26
-rw-r--r--ogcp/templates/commands.html2
-rw-r--r--ogcp/views.py43
4 files changed, 69 insertions, 8 deletions
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 %}
+<h1 class="m-5">
+ {{ _('Partitioning %(ip_count)d client(s)', ip_count=ip_count) }}
+</h1>
+
+{{ 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 @@
<input class="btn btn-light dropdown-item{% block nav_setup_set_oglive %}{% endblock %}" type="submit" value="{{ _('Set ogLive') }}"
form="scopesForm" formaction="{{ url_for('action_oglive') }}" formmethod="get">
<input class="btn btn-light dropdown-item{% block nav_setup_setup %}{% endblock %}" type="submit" value="{{ _('Partition & Format') }}"
- form="scopesForm" formaction="{{ url_for('action_setup_show') }}" formmethod="get">
+ form="scopesForm" formaction="{{ url_for('action_setup_select') }}" formmethod="get">
</div>
</div>
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