From 4c4d3f68203e625f596ab02abe3f10ae40b57693 Mon Sep 17 00:00:00 2001 From: Cristian Torres Date: Sun, 7 Mar 2021 01:07:11 -0600 Subject: [PATCH 1/3] When value is a list it should be returned as is This change should help close #1103 --- django_filters/widgets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django_filters/widgets.py b/django_filters/widgets.py index 889fd812b..14b2142d6 100644 --- a/django_filters/widgets.py +++ b/django_filters/widgets.py @@ -210,6 +210,10 @@ def value_from_datadict(self, data, files, name): if value is not None: if value == '': # empty value should parse as an empty list return [] + if isinstance(value, list): + # since django.forms.widgets.SelectMultiple tries to use getlist + # if available, we should return value if it's already an array + return value return value.split(',') return None From 0e4ccdd022cef2c6056ad5e3dcedb0627d31a796 Mon Sep 17 00:00:00 2001 From: bryan brancotte Date: Fri, 26 Jan 2024 10:22:14 +0100 Subject: [PATCH 2/3] Update test_widgets.py Check list are now accepted --- tests/test_widgets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_widgets.py b/tests/test_widgets.py index e011756a6..930da8ee2 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -310,6 +310,10 @@ class NumberCSVWidget(BaseCSVWidget, NumberInput): result = w.value_from_datadict(data, {}, 'price') self.assertEqual(result, ['1', '2']) + data = {'price': ['1', '2']} + result = w.value_from_datadict(data, {}, 'price') + self.assertEqual(result, ['1', '2']) + data = {'price': '1,,2'} result = w.value_from_datadict(data, {}, 'price') self.assertEqual(result, ['1', '', '2']) From a8ff9786c56a3c3bbc73b9d598728cb7416e544e Mon Sep 17 00:00:00 2001 From: Bryan Brancotte Date: Fri, 26 Jan 2024 10:44:19 +0100 Subject: [PATCH 3/3] fixing formatting --- django_filters/widgets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_filters/widgets.py b/django_filters/widgets.py index 8d3583310..f5c99b117 100644 --- a/django_filters/widgets.py +++ b/django_filters/widgets.py @@ -205,8 +205,8 @@ def value_from_datadict(self, data, files, name): if value is not None: if value == "": # empty value should parse as an empty list return [] - if isinstance(value, list): - # since django.forms.widgets.SelectMultiple tries to use getlist + if isinstance(value, list): + # since django.forms.widgets.SelectMultiple tries to use getlist # if available, we should return value if it's already an array return value return value.split(",")