test list field
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 24 May 2010 10:07:58 +0000 (10:07 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 24 May 2010 10:07:58 +0000 (10:07 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@870 e071eeec-0327-468d-9b6a-08194a12b294

ldapdb/models/fields.py
ldapdb/tests.py

index 921923c052469ac826248bde9743b57d48c66ed6..5e85062407847b2a7735ec0b83eece3c38c7a427 100644 (file)
@@ -59,19 +59,35 @@ class CharField(fields.CharField):
 
 class ImageField(fields.Field):
     def get_db_prep_lookup(self, lookup_type, value):
+        "Returns field's value prepared for database lookup."
+        return [self.get_prep_lookup(lookup_type, value)]
+
+    def get_prep_lookup(self, lookup_type, value):
+        "Perform preliminary non-db specific lookup checks and conversions"
         raise TypeError("ImageField has invalid lookup: %s" % lookup_type)
 
 class IntegerField(fields.IntegerField):
     def get_db_prep_lookup(self, lookup_type, value):
-        if lookup_type in ('exact', 'gte', 'lte'):
-            return [value]
+        "Returns field's value prepared for database lookup."
+        return [self.get_prep_lookup(lookup_type, value)]
 
+    def get_prep_lookup(self, lookup_type, value):
+        "Perform preliminary non-db specific lookup checks and conversions"
+        if lookup_type in ('exact', 'gte', 'lte'):
+            return value
         raise TypeError("IntegerField has invalid lookup: %s" % lookup_type)
 
 class ListField(fields.Field):
     __metaclass__ = SubfieldBase
 
     def get_db_prep_lookup(self, lookup_type, value):
+        "Returns field's value prepared for database lookup."
+        return [self.get_prep_lookup(lookup_type, value)]
+
+    def get_prep_lookup(self, lookup_type, value):
+        "Perform preliminary non-db specific lookup checks and conversions"
+        if lookup_type == 'contains':
+            return escape_ldap_filter(value)
         raise TypeError("ListField has invalid lookup: %s" % lookup_type)
 
     def to_python(self, value):
index f9c4b1674a3df4a74143d75268d79b19fd3d76a3..6d5c8b5c29e4833d02bfbfdeaabd9ecfd00817d2 100644 (file)
@@ -91,6 +91,11 @@ class WhereTestCase(TestCase):
         where.add((Constraint("uid", "uid", IntegerField()), 'lte', 1), AND)
         self.assertEquals(where.as_sql(), "(uid<=1)")
 
+    def test_list_field_contains(self):
+        where = WhereNode()
+        where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', 'foouser'), AND)
+        self.assertEquals(where.as_sql(), "(memberUid=foouser)")
+
     def test_and(self):
         where = WhereNode()
         where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND)