mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
Fix for filtering using __int on boolean fields.
This commit is contained in:
parent
22af7cf6b0
commit
718b566a03
@ -61,6 +61,7 @@ class FieldLookupBackend(BaseFilterBackend):
|
||||
return field
|
||||
|
||||
def to_python_boolean(self, value, allow_none=False):
|
||||
value = unicode(value)
|
||||
if value.lower() in ('true', '1'):
|
||||
return True
|
||||
elif value.lower() in ('false', '0'):
|
||||
@ -71,6 +72,7 @@ class FieldLookupBackend(BaseFilterBackend):
|
||||
raise ValueError(u'Unable to convert "%s" to boolean' % unicode(value))
|
||||
|
||||
def to_python_related(self, value):
|
||||
value = unicode(value)
|
||||
if value.lower() in ('none', 'null'):
|
||||
return None
|
||||
else:
|
||||
|
||||
@ -406,6 +406,12 @@ class UsersTest(BaseTest):
|
||||
url = '%s?is_superuser=notatbool' % base_url
|
||||
self.check_get_list(url, self.super_django_user, base_qs, expect=400)
|
||||
|
||||
# Filter by custom __int suffix on boolean field.
|
||||
url = '%s?is_superuser__int=1' % base_url
|
||||
qs = base_qs.filter(is_superuser=True)
|
||||
self.assertTrue(qs.count())
|
||||
self.check_get_list(url, self.super_django_user, qs)
|
||||
|
||||
# Filter by is_staff (field not exposed via API). FIXME: Should
|
||||
# eventually not be allowed!
|
||||
url = '%s?is_staff=true' % base_url
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user