mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Use contains for search
query in SmartFilter
This commit is contained in:
parent
903e3076aa
commit
356a2bc057
@ -114,13 +114,13 @@ class TestSmartFilterQueryFromString():
|
||||
|
||||
|
||||
@pytest.mark.parametrize("filter_string,q_expected", [
|
||||
('search=foo', Q(Q(**{u"name": u"foo"}) | Q(**{ u"description": u"foo"}))),
|
||||
('group__search=foo', Q(Q(**{u"group__name": u"foo"}) | Q(**{u"group__description": u"foo"}))),
|
||||
('search=foo', Q(Q(**{u"name__contains": u"foo"}) | Q(**{ u"description__contains": u"foo"}))),
|
||||
('group__search=foo', Q(Q(**{u"group__name__contains": u"foo"}) | Q(**{u"group__description__contains": u"foo"}))),
|
||||
('search=foo and group__search=foo', Q(
|
||||
Q(**{u"name": u"foo"}) | Q(**{ u"description": u"foo"}),
|
||||
Q(**{u"group__name": u"foo"}) | Q(**{u"group__description": u"foo"}))),
|
||||
Q(**{u"name__contains": u"foo"}) | Q(**{ u"description__contains": u"foo"}),
|
||||
Q(**{u"group__name__contains": u"foo"}) | Q(**{u"group__description__contains": u"foo"}))),
|
||||
('search=foo or ansible_facts__a=null',
|
||||
Q(Q(**{u"name": u"foo"}) | Q(**{u"description": u"foo"})) |
|
||||
Q(Q(**{u"name__contains": u"foo"}) | Q(**{u"description__contains": u"foo"})) |
|
||||
Q(**{u"ansible_facts__contains": {u"a": u"null"}})),
|
||||
])
|
||||
def test_search_related_fields(self, mock_get_host_model, filter_string, q_expected):
|
||||
|
@ -51,7 +51,7 @@ class SmartFilter(object):
|
||||
search_kwargs = self._expand_search(k, v)
|
||||
if search_kwargs:
|
||||
kwargs.update(search_kwargs)
|
||||
q = reduce(lambda x, y: x | y, [django.db.models.Q(**{u'%s' % _k:_v}) for _k, _v in kwargs.items()])
|
||||
q = reduce(lambda x, y: x | y, [django.db.models.Q(**{u'%s__contains' % _k:_v}) for _k, _v in kwargs.items()])
|
||||
self.result = Host.objects.filter(q)
|
||||
else:
|
||||
kwargs[k] = v
|
||||
|
Loading…
Reference in New Issue
Block a user