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
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),
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
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),
# 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)