add db prep
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Wed, 19 May 2010 08:21:36 +0000 (08:21 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Wed, 19 May 2010 08:21:36 +0000 (08:21 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@847 e071eeec-0327-468d-9b6a-08194a12b294

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

index 78ec1c7569f3421d2b856e2d78856f70cbed70da..88b52522814bf259ec164a731ad3b265be686fd9 100644 (file)
@@ -25,6 +25,19 @@ class CharField(fields.CharField):
         kwargs['max_length'] = 200
         super(CharField, self).__init__(*args, **kwargs)
 
+    def get_db_prep_value(self, value):
+        """Returns field's value prepared for interacting with the database
+        backend.
+
+        Used by the default implementations of ``get_db_prep_save``and
+        `get_db_prep_lookup```
+        """
+        return value.replace('\\', '\\5c')
+                    .replace('*', '\\2a')
+                    .replace('(', '\\28')
+                    .replace(')', '\\29')
+                    .replace('\0', '\\00')
+
 class ImageField(fields.Field):
     pass
 
index d64ff4625a354ee00796591174db70cdb27b1ea9..e3c787b008d3db8a7100a73f88943670cbd11cbf 100644 (file)
 from django.test import TestCase
 from django.db.models.sql.where import Constraint, AND, OR
 
+from ldapdb.models.fields import CharField
 from ldapdb.models.query import WhereNode
 
+class FieldTestCase(TestCase):
+    def test_db_prep(self):
+        field = CharField()
+
 class WhereTestCase(TestCase):
     def test_single(self):
         where = WhereNode()