From 26178aed79f88bec01122855fa0661d166355744 Mon Sep 17 00:00:00 2001 From: jlaine Date: Mon, 31 May 2010 19:38:39 +0000 Subject: [PATCH] rework ldap filtering git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@908 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/models/query.py | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 5b7e6af..0d4b0e1 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -71,22 +71,14 @@ class Compiler(object): def results_iter(self): query = self.query - - filterstr = ''.join(['(objectClass=%s)' % cls for cls in query.model.object_classes]) - sql, params = query.where.as_sql() - filterstr += sql - filterstr = '(&%s)' % filterstr attrlist = [ x.db_column for x in query.model._meta.local_fields if x.db_column ] - try: - vals = self.connection.search_s( - query.model.base_dn, - ldap.SCOPE_SUBTREE, - filterstr=filterstr, - attrlist=attrlist, - ) - except: - raise query.model.DoesNotExist + vals = self.connection.search_s( + query.model.base_dn, + ldap.SCOPE_SUBTREE, + filterstr=query._ldap_filter(), + attrlist=attrlist, + ) # perform sorting if query.extra_order_by: @@ -187,22 +179,19 @@ class Query(BaseQuery): super(Query, self).__init__(*args, **kwargs) self.connection = ldapdb.connection - def get_count(self, using=None): + def _ldap_filter(self): filterstr = ''.join(['(objectClass=%s)' % cls for cls in self.model.object_classes]) sql, params = self.where.as_sql() filterstr += sql - filterstr = '(&%s)' % filterstr - - try: - vals = ldapdb.connection.search_s( - self.model.base_dn, - ldap.SCOPE_SUBTREE, - filterstr=filterstr, - attrlist=[], - ) - except: - raise self.model.DoesNotExist + return '(&%s)' % filterstr + def get_count(self, using=None): + vals = ldapdb.connection.search_s( + self.model.base_dn, + ldap.SCOPE_SUBTREE, + filterstr=self._ldap_filter(), + attrlist=[], + ) return len(vals) def get_compiler(self, using=None, connection=None): -- 2.30.2