"""
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.
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
try:
vals = self.connection.search_s(
self.query.model.base_dn,
- ldap.SCOPE_SUBTREE,
+ self.query.model.search_scope,
filterstr=self.query._ldap_filter(),
attrlist=attrlist,
)
else:
clause = '(|%s)' % ''.join(equal_bits)
- if self.negated:
- bits.append('(!%s)' % clause)
- else:
- bits.append(clause)
+ bits.append(clause)
+
+ if not len(bits):
+ return '', []
+
if len(bits) == 1:
sql_string = bits[0]
elif self.connector == AND:
sql_string = '(|%s)' % ''.join(bits)
else:
raise Exception("Unhandled WHERE connector: %s" % self.connector)
+
+ if self.negated:
+ sql_string = ('(!%s)' % sql_string)
+
return sql_string, []
class Query(BaseQuery):
try:
vals = ldapdb.connection.search_s(
self.model.base_dn,
- ldap.SCOPE_SUBTREE,
+ self.model.search_scope,
filterstr=self._ldap_filter(),
attrlist=[],
)
def get_compiler(self, using=None, connection=None):
return Compiler(self, ldapdb.connection, using)
+ def has_results(self, using):
+ return self.get_count() != 0
+
def results_iter(self):
"For django 1.1 compatibility"
return self.get_compiler().results_iter()
try:
vals = ldapdb.connection.search_s(
self.model.base_dn,
- ldap.SCOPE_SUBTREE,
+ self.model.search_scope,
filterstr=self.query._ldap_filter(),
attrlist=[],
)