-class Query(BaseQuery):
- def results_iter(self):
- # FIXME: use all object classes
- filterstr = '(objectClass=%s)' % self.model._meta.object_classes[0]
- filterstr += compile(self.where)
- filterstr = '(&%s)' % filterstr
- attrlist = [ x.db_column for x in self.model._meta.local_fields if x.db_column ]
+from ldapdb.backends.ldap import compiler
+from ldapdb.models.fields import CharField
+
+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.
+ """
+ def process(self, lookup_type, value, connection):
+ """
+ Returns a tuple of data suitable for inclusion in a WhereNode
+ instance.
+ """
+ # Because of circular imports, we need to import this here.
+ from django.db.models.base import ObjectDoesNotExist
+
+ try:
+ if self.field:
+ 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,
+ connection=connection, prepared=True)
+ db_type = None
+ except ObjectDoesNotExist:
+ raise EmptyShortCircuit
+
+ return (self.alias, self.col, db_type), params
+
+class WhereNode(BaseWhereNode):
+ def add(self, data, connector):
+ if not isinstance(data, (list, tuple)):
+ super(WhereNode, self).add(data, connector)
+ return