From 5c3683a37e2afc87654d4b44c3f8e9fbe7872076 Mon Sep 17 00:00:00 2001 From: jlaine Date: Tue, 29 Mar 2011 11:08:21 +0000 Subject: [PATCH] convert get_db_prep_lookup() to new style (django 1.2+) git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1009 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/models/fields.py | 8 ++++---- ldapdb/models/query.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ldapdb/models/fields.py b/ldapdb/models/fields.py index 752bc9f..cbb1c40 100644 --- a/ldapdb/models/fields.py +++ b/ldapdb/models/fields.py @@ -47,7 +47,7 @@ class CharField(fields.CharField): else: return value[0].decode(connection.charset) - def get_db_prep_lookup(self, lookup_type, value): + def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): "Returns field's value prepared for database lookup." if lookup_type == 'endswith': return ["*%s" % escape_ldap_filter(value)] @@ -87,7 +87,7 @@ class ImageField(fields.Field): else: return value[0] - def get_db_prep_lookup(self, lookup_type, value): + def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): "Returns field's value prepared for database lookup." return [self.get_prep_lookup(lookup_type, value)] @@ -105,7 +105,7 @@ class IntegerField(fields.IntegerField): else: return int(value[0]) - def get_db_prep_lookup(self, lookup_type, value): + def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): "Returns field's value prepared for database lookup." return [self.get_prep_lookup(lookup_type, value)] @@ -124,7 +124,7 @@ class ListField(fields.Field): def from_ldap(self, value, connection): return value - def get_db_prep_lookup(self, lookup_type, value): + def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False): "Returns field's value prepared for database lookup." return [self.get_prep_lookup(lookup_type, value)] diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 1fddeee..91a3f62 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -56,8 +56,13 @@ class Constraint(BaseConstraint): """ An object that can be passed to WhereNode.add() and knows how to pre-process itself prior to including in the WhereNode. + + NOTES: + - we redefine this class, because when self.field is None calls + Field().get_db_prep_lookup(), which short-circuits our LDAP-specific code. + - the connection argument defaults to None for django 1.1 compatibility """ - def process(self, lookup_type, value): + def process(self, lookup_type, value, connection=None): """ Returns a tuple of data suitable for inclusion in a WhereNode instance. @@ -67,10 +72,12 @@ class Constraint(BaseConstraint): try: if self.field: - params = self.field.get_db_prep_lookup(lookup_type, value) + params = self.field.get_db_prep_lookup(lookup_type, value, + connection=connection, prepared=True) db_type = self.field.db_type() else: - params = CharField().get_db_prep_lookup(lookup_type, value) + params = CharField().get_db_prep_lookup(lookup_type, value, + connection=connection, prepared=True) db_type = None except ObjectDoesNotExist: raise EmptyShortCircuit -- 2.30.2