From 12018b1a67c70ddf822c4c9f5c8909b3de088a54 Mon Sep 17 00:00:00 2001 From: jlaine Date: Mon, 11 Apr 2011 10:47:20 +0000 Subject: [PATCH] use django's database framework instead of hard-coding ldapdb.connection git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1026 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/models/query.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 2b82376..8fe595f 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -35,12 +35,12 @@ from copy import deepcopy import ldap +from django.db import connections from django.db.models.query import QuerySet as BaseQuerySet from django.db.models.query_utils import Q from django.db.models.sql import Query as BaseQuery from django.db.models.sql.where import WhereNode as BaseWhereNode, Constraint as BaseConstraint, AND, OR -import ldapdb from ldapdb.backends.ldap import compiler from ldapdb.models.fields import CharField @@ -89,8 +89,9 @@ class WhereNode(BaseWhereNode): class Query(BaseQuery): def get_count(self, using): + connection = connections[using] try: - vals = ldapdb.connection.search_s( + vals = connection.search_s( self.model.base_dn, self.model.search_scope, filterstr=compiler.query_as_ldap(self), @@ -108,9 +109,6 @@ class Query(BaseQuery): return number - def get_compiler(self, using=None, connection=None): - return super(Query, self).get_compiler(connection=ldapdb.connection) - def has_results(self, using): return self.get_count(using) != 0 @@ -122,8 +120,9 @@ class QuerySet(BaseQuerySet): def delete(self): "Bulk deletion." + connection = connections[self.db] try: - vals = ldapdb.connection.search_s( + vals = connection.search_s( self.model.base_dn, self.model.search_scope, filterstr=compiler.query_as_ldap(self.query), @@ -134,5 +133,5 @@ class QuerySet(BaseQuerySet): # FIXME : there is probably a more efficient way to do this for dn, attrs in vals: - ldapdb.connection.delete_s(dn) + connection.delete_s(dn) -- 2.30.2