Fix the problem that patch upload fails of horizon
fb4c55d9ec
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 <wentao.zhang@windriver.com>
This commit is contained in:
parent
8121f7d24d
commit
7ce032a639
|
@ -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
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from django.forms import FileField
|
||||||
from django.forms import FileInput
|
from django.forms import FileInput
|
||||||
from django.urls import reverse # noqa
|
from django.urls import reverse # noqa
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
@ -22,13 +23,27 @@ class MultipleFileInput(FileInput):
|
||||||
allow_multiple_selected = True
|
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):
|
class UploadPatchForm(forms.SelfHandlingForm):
|
||||||
failure_url = 'horizon:admin:software_management:index'
|
failure_url = 'horizon:admin:software_management:index'
|
||||||
patch_files = forms.FileField(label=_("Patch File(s)"),
|
patch_files = MultipleFileField(
|
||||||
widget=MultipleFileInput(attrs={
|
label=_("Patch File(s)"),
|
||||||
'data-source-file': _('Patch File(s)'),
|
widget=MultipleFileInput(attrs={
|
||||||
'multiple': "multiple"}),
|
'data-source-file': _('Patch File(s)'),
|
||||||
required=True)
|
'multiple': "multiple"}), required=True)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(UploadPatchForm, self).__init__(*args, **kwargs)
|
super(UploadPatchForm, self).__init__(*args, **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue