Rewrite getForFields to use GQL instead of the Query API
Apparently the Query API does not support the IN statement.
Patch by: Sverre Rabbelier
--- 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:
--- 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