X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=ldapdb%2Fmodels%2Fquery.py;h=a8c614f7ccfe6a2ee487ac35b38bb474951efa0c;hb=ab216ac000ca0b6aeea64d9ce112395bbb7962d5;hp=5f522a61cd17b43cf94a91af28ce00dad7a72cf8;hpb=23a36d706cedeed4d02d0f97b46669403ce5b943;p=matthijs%2Fupstream%2Fdjango-ldapdb.git diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index 5f522a6..a8c614f 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -28,7 +28,15 @@ from django.db.models.sql.where import WhereNode as BaseWhereNode, Constraint as import ldapdb -from ldapdb import escape_ldap_filter +from ldapdb.models.fields import CharField + +def get_lookup_operator(lookup_type): + if lookup_type == 'gte': + return '>=' + elif lookup_type == 'lte': + return '<=' + else: + return '=' class Constraint(BaseConstraint): """ @@ -43,23 +51,12 @@ class Constraint(BaseConstraint): # Because of circular imports, we need to import this here. from django.db.models.base import ObjectDoesNotExist - if lookup_type == 'endswith': - params = ["*%s" % escape_ldap_filter(value)] - elif lookup_type == 'startswith': - params = ["%s*" % escape_ldap_filter(value)] - elif lookup_type == 'contains': - params = ["*%s*" % escape_ldap_filter(value)] - elif lookup_type == 'exact': - params = [escape_ldap_filter(value)] - elif lookup_type == 'in': - params = [escape_ldap_filter(v) for v in value] - else: - raise TypeError("Field has invalid lookup: %s" % lookup_type) - try: if self.field: + params = self.field.get_db_prep_lookup(lookup_type, value) db_type = self.field.db_type() else: + params = CharField().get_db_prep_lookup(lookup_type, value) db_type = None except ObjectDoesNotExist: raise EmptyShortCircuit @@ -87,11 +84,13 @@ class WhereNode(BaseWhereNode): constraint, x, y, values = item if hasattr(constraint, "col"): # django 1.2 - clause = "(%s=%s)" % (constraint.col, values) + comp = get_lookup_operator(constraint.lookup_type) + clause = "(%s%s%s)" % (constraint.col, comp, values) else: # django 1.1 - (table, column, type) = constraint - equal_bits = [ "(%s=%s)" % (column, value) for value in values ] + (table, column, db_type) = constraint + comp = get_lookup_operator(x) + equal_bits = [ "(%s%s%s)" % (column, comp, value) for value in values ] if len(equal_bits) == 1: clause = equal_bits[0] else: