From 7ce032a63910990dfcecbc4d81833f4cc0879cc1 Mon Sep 17 00:00:00 2001 From: Wentao Zhang Date: Fri, 3 Nov 2023 11:43:00 +0800 Subject: [PATCH] Fix the problem that patch upload fails of horizon https://github.com/django/django/commit/fb4c55d9ec4bb812a7fb91fa20510d91645e411b This commit disables FileField for uploading multiple files directly and introduces a new method as a replacement. the upgrade of python3-django from 2:2.2.28-1~deb11u1 to 2:2.2.28-1~deb11u2 includes this commit. Replace FileField with MultipleFileField for uploading multiple files. Refer to the method introduced in the commit to replace the previous usage. Test Plan PASS: build-pkgs -c -p starlingx-dashboard && build-image PASS: jenkins installation successfuly PASS: upload a patch using Horizon Web interface successfully Closes-Bug: 2042610 Change-Id: I7bb4a0db7621922e5f1c8811ec3f49be4a37d1a5 Signed-off-by: Wentao Zhang --- .../admin/software_management/forms.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/forms.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/forms.py index eb7d39c8..acf01201 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/forms.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/forms.py @@ -1,11 +1,12 @@ # -# Copyright (c) 2016-2020 Wind River Systems, Inc. +# Copyright (c) 2016-2023 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # import logging +from django.forms import FileField from django.forms import FileInput from django.urls import reverse # noqa from django.utils.translation import ugettext_lazy as _ @@ -22,13 +23,27 @@ class MultipleFileInput(FileInput): allow_multiple_selected = True +class MultipleFileField(FileField): + def __init__(self, *args, **kwargs): + kwargs.setdefault("widget", MultipleFileInput()) + super().__init__(*args, **kwargs) + + def clean(self, data, initial=None): + single_file_clean = super().clean + if isinstance(data, (list, tuple)): + result = [single_file_clean(d, initial) for d in data] + else: + result = single_file_clean(data, initial) + return result + + class UploadPatchForm(forms.SelfHandlingForm): failure_url = 'horizon:admin:software_management:index' - patch_files = forms.FileField(label=_("Patch File(s)"), - widget=MultipleFileInput(attrs={ - 'data-source-file': _('Patch File(s)'), - 'multiple': "multiple"}), - required=True) + patch_files = MultipleFileField( + label=_("Patch File(s)"), + widget=MultipleFileInput(attrs={ + 'data-source-file': _('Patch File(s)'), + 'multiple': "multiple"}), required=True) def __init__(self, *args, **kwargs): super(UploadPatchForm, self).__init__(*args, **kwargs)