Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Clean method for customer search

Marcin Gębala4b5f311fcfae
diff --git a/saleor/dashboard/customer/forms.py b/saleor/dashboard/customer/forms.py
index 9c2a5e55a6..3fbebe86b4 100644
--- a/saleor/dashboard/customer/forms.py
+++ b/saleor/dashboard/customer/forms.py
@@ -5,3 +5,12 @@ from django.utils.translation import ugettext_lazy as _
class CustomerSearchForm(forms.Form):
email = forms.CharField(required=False, label=_('Email'))
name = forms.CharField(required=False, label=_('Name'))
+
+ def clean(self):
+ data = self.cleaned_data
+ if not any(data.values()):
+ raise forms.ValidationError(
+ _('At least one field must be specified'), code='invalid')
+ for k in data.keys():
+ data[k] = data[k].strip()
+ return data
diff --git a/saleor/dashboard/customer/views.py b/saleor/dashboard/customer/views.py
index 21e01f6c15..caefe3accb 100644
--- a/saleor/dashboard/customer/views.py
+++ b/saleor/dashboard/customer/views.py
@@ -8,8 +8,6 @@ from ...userprofile.models import User
def _search_customers(queryset, data):
- for k in data.keys():
- data[k] = data[k].strip()
if data['email']:
queryset = queryset.filter(email__icontains=data['email'])
if data['name']: