add support for 'contains' filter (Jeff Schroeder)
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Wed, 19 May 2010 13:25:18 +0000 (13:25 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Wed, 19 May 2010 13:25:18 +0000 (13:25 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@850 e071eeec-0327-468d-9b6a-08194a12b294

ldapdb/models/query.py
ldapdb/tests.py

index 877ea9e40ee74c0b323361e39ca2ea893ba79f4f..49c183e5432f900bde835098917f9197df0cc251 100644 (file)
@@ -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':
index be247fdbb05a06a830c4c7d3c2b3ea210b039d7d..1e328ec5ffecf6ddf947896704cf1b21986c3759 100644 (file)
@@ -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)