# HG changeset patch # User Sverre Rabbelier # Date 1233586029 0 # Node ID 427d2ec42823de55180d037a77428e98508e4ec0 # Parent f0de31a147978d0478e7ed4c04cb43b4dec7c1ab Rewrite getForFields to use GQL instead of the Query API Apparently the Query API does not support the IN statement. Patch by: Sverre Rabbelier diff -r f0de31a14797 -r 427d2ec42823 app/soc/logic/models/base.py --- a/app/soc/logic/models/base.py Mon Feb 02 14:19:22 2009 +0000 +++ b/app/soc/logic/models/base.py Mon Feb 02 14:47:09 2009 +0000 @@ -289,12 +289,30 @@ if unique: limit = 1 - q = db.Query(self._model) + format_eq = '%(key)s = :%(num)d' + format_in = '%(key)s IN (%(values)s)' + + n = 1 + conditionals = [] + args = [] - for key, values in filter.iteritems(): - for value in (values if isinstance(values, list) else [values]): - q.filter(key, value) + for key, value in filter.iteritems(): + if isinstance(value, list): + count = len(value) + args.extend(value) + values = ', '.join([':%d' % i for i in range(n, n + count)]) + sub = format_in % {'key': key, 'values': values} + n = n + count + else: + sub = format_eq % {'key': key, 'num': n} + args.append(value) + n = n + 1 + conditionals.append(sub) + joined_pairs = ' AND '.join(conditionals) + condition = 'WHERE ' + joined_pairs + + q = self._model.gql(condition, *args) result = q.fetch(limit, offset) if unique: diff -r f0de31a14797 -r 427d2ec42823 app/soc/views/helper/access.py --- a/app/soc/views/helper/access.py Mon Feb 02 14:19:22 2009 +0000 +++ b/app/soc/views/helper/access.py Mon Feb 02 14:47:09 2009 +0000 @@ -535,13 +535,13 @@ fields = { filter_field: django_args[filter_field], - 'status': active, + 'status': 'active', } if field_name: fields['scope_path'] = django_args[field_name] - entity = logic.geForFields(fields) + entity = logic.getForFields(fields, unique=True) if entity: return