X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fdjango-ldapdb.git;a=blobdiff_plain;f=ldapdb%2Fmodels%2Fquery.py;h=bbb46e2553f991e124bbcbc16d1ee3bed0d71beb;hp=fc211b45715099f3e48c2ca3eb489635249c921b;hb=82901736cde9aae9fbe8b6acc0aad2141ecd9583;hpb=bccb982d735bb0a2d6d83fa545389ca9ac831ab8 diff --git a/ldapdb/models/query.py b/ldapdb/models/query.py index fc211b4..bbb46e2 100644 --- a/ldapdb/models/query.py +++ b/ldapdb/models/query.py @@ -96,15 +96,20 @@ class Compiler(object): else: ordering = query.order_by or query.model._meta.ordering def cmpvals(x, y): - for field in ordering: - if field.startswith('-'): - field = field[1:] + for fieldname in ordering: + if fieldname.startswith('-'): + fieldname = fieldname[1:] negate = True else: negate = False - attr = query.model._meta.get_field(field).db_column - attr_x = x[1].get(attr, '').lower() - attr_y = y[1].get(attr, '').lower() + field = query.model._meta.get_field(fieldname) + attr_x = field.from_ldap(x[1].get(field.db_column, []), connection=self.connection) + attr_y = field.from_ldap(y[1].get(field.db_column, []), connection=self.connection) + # perform case insensitive comparison + if hasattr(attr_x, 'lower'): + attr_x = attr_x.lower() + if hasattr(attr_y, 'lower'): + attr_y = attr_y.lower() val = negate and cmp(attr_y, attr_x) or cmp(attr_x, attr_y) if val: return val