From 45c9e99629c4af8f559b64ee57c3527af628032c Mon Sep 17 00:00:00 2001 From: jlaine Date: Wed, 19 May 2010 13:25:18 +0000 Subject: [PATCH] add support for 'contains' filter (Jeff Schroeder) git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@850 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/models/query.py | 2 ++ ldapdb/tests.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 877ea9e..49c183e 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -53,6 +53,8 @@ class Constraint(BaseConstraint): params = ["*%s" % escape_ldap_filter(value)] elif lookup_type == 'startswith': params = ["%s*" % escape_ldap_filter(value)] + elif lookup_type == 'contains': + params = ["*%s*" % escape_ldap_filter(value)] elif lookup_type == 'exact': params = [escape_ldap_filter(value)] elif lookup_type == 'in': diff --git a/ldapdb/tests.py b/ldapdb/tests.py index be247fd..1e328ec 100644 --- a/ldapdb/tests.py +++ b/ldapdb/tests.py @@ -49,6 +49,10 @@ class WhereTestCase(TestCase): where.add((Constraint("cn", "cn", None), 'in', ["foo", "bar"]), AND) self.assertEquals(where.as_sql(), "(|(cn=foo)(cn=bar))") + where = WhereNode() + where.add((Constraint("cn", "cn", None), 'contains', "test"), AND) + self.assertEquals(where.as_sql(), "(cn=*test*)") + def test_escaped(self): where = WhereNode() where.add((Constraint("cn", "cn", None), 'exact', "(test)"), AND) -- 2.30.2