From d9597e4e014dc150b4a56bc6d7c5972b1b361885 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 13 Feb 2025 10:25:00 +0100 Subject: [PATCH] views: fix partition scheme default values Assign EMPTY when no scheme code is found. Select GPT by default when the partition scheme is EMPTY in partition and format view. Add missing EMPTY value to SetupForm. --- ogcp/forms/action_forms.py | 3 ++- ogcp/views.py | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 4d5d52a..5417ca5 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -73,7 +73,8 @@ class SetupForm(FlaskForm): ips = HiddenField() disk = SelectField(label='Disk', validate_choice=False) disk_type = SelectField(label=_l('Type'), - choices=[('MSDOS', 'MBR'), + choices=[('EMPTY', 'EMPTY'), + ('MSDOS', 'MBR'), ('GPT', 'GPT')]) partitions = FieldList(FormField(PartitionForm), min_entries=1, diff --git a/ogcp/views.py b/ogcp/views.py index ef64ade..53acbd8 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -183,7 +183,7 @@ def get_client_setup(ip): res = {} for partition in db_partitions: if partition['partition'] == 0: - partition['code'] = PART_SCHEME_CODES.get(partition['code'], 'MSDOS') + partition['code'] = PART_SCHEME_CODES.get(partition['code'], 'EMPTY') else: partition['code'] = PART_TYPE_CODES.get(partition['code'], 'EMPTY') @@ -794,8 +794,11 @@ def action_setup_show(): form.disk.choices = [(disk, disk) for disk in setup_data] form.disk.data = selected_disk - # If partition table is empty, set MSDOS - form.disk_type.data = setup_data[selected_disk][0]['code'] or 1 + + for disk in setup_data: + if setup_data[disk][0]['code'] == 'EMPTY': + setup_data[disk][0]['code'] = 'GPT' + form.disk_type.data = setup_data[selected_disk][0]['code'] scopes, _clients = get_scopes(ips) return render_template('actions/setup.html',