From 5b97fccb66efc67de3ce0165528cd454b2245ddc Mon Sep 17 00:00:00 2001 From: jlaine Date: Wed, 19 May 2010 08:21:36 +0000 Subject: [PATCH] add db prep git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@847 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/models/fields.py | 13 +++++++++++++ ldapdb/tests.py | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/ldapdb/models/fields.py b/ldapdb/models/fields.py index 78ec1c7..88b5252 100644 --- a/ldapdb/models/fields.py +++ b/ldapdb/models/fields.py @@ -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 diff --git a/ldapdb/tests.py b/ldapdb/tests.py index d64ff46..e3c787b 100644 --- a/ldapdb/tests.py +++ b/ldapdb/tests.py @@ -21,8 +21,13 @@ 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() -- 2.30.2