aboutsummaryrefslogtreecommitdiffstats
path: root/layerindex/querysethelper.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-07-04 09:50:12 +1200
committerPaul Eggleton <paul.eggleton@linux.intel.com>2016-07-04 09:51:21 +1200
commit1d76228675e93add50dd5216c43e00f977e1aaa8 (patch)
treebd24425f27f5f4bd7dc6f2ff64aae844c41cae54 /layerindex/querysethelper.py
parent76a1ab669afc99b453e482477d04be09ab125978 (diff)
downloadopenembedded-core-contrib-1d76228675e93add50dd5216c43e00f977e1aaa8.tar.gz
Use functools.reduce instead of reduce
This is apparently required in Python 3.3+, although I have been unable to verify this locally. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'layerindex/querysethelper.py')
-rw-r--r--layerindex/querysethelper.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/layerindex/querysethelper.py b/layerindex/querysethelper.py
index 8d54d76bea..6c8daa41b5 100644
--- a/layerindex/querysethelper.py
+++ b/layerindex/querysethelper.py
@@ -1,4 +1,5 @@
import operator
+import functools
from django.db.models import Q
def _verify_parameters(g, mandatory_parameters):
@@ -28,9 +29,9 @@ DESCENDING = "-"
def __get_q_for_val(name, value):
if "OR" in value:
- return reduce(operator.or_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("OR") ]))
+ return functools.reduce(operator.or_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("OR") ]))
if "AND" in value:
- return reduce(operator.and_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("AND") ]))
+ return functools.reduce(operator.and_, map(lambda x: __get_q_for_val(name, x), [ x for x in value.split("AND") ]))
if value.startswith("NOT"):
kwargs = { name : value.strip("NOT") }
return ~Q(**kwargs)
@@ -45,7 +46,7 @@ def _get_filtering_query(filter_string):
values = search_terms[1].split(VALUE_SEPARATOR)
querydict = dict(zip(keys, values))
- return reduce(operator.and_, map(lambda x: __get_q_for_val(x, querydict[x]), [k for k in querydict]))
+ return functools.reduce(operator.and_, map(lambda x: __get_q_for_val(x, querydict[x]), [k for k in querydict]))
# we check that the input comes in a valid form that we can recognize
def _validate_input(input, model):
@@ -68,7 +69,7 @@ def _validate_input(input, model):
# Check we are looking for a valid field
valid_fields = model._meta.get_all_field_names()
for field in input_list[0].split(VALUE_SEPARATOR):
- if not reduce(lambda x, y: x or y, map(lambda x: field.startswith(x), [ x for x in valid_fields ])):
+ if not functools.reduce(lambda x, y: x or y, map(lambda x: field.startswith(x), [ x for x in valid_fields ])):
return None, (field, [ x for x in valid_fields ])
return input, invalid
@@ -81,8 +82,8 @@ def _get_search_results(search_term, queryset, model):
q_map = map(lambda x: Q(**{x+'__icontains': st}),
model.search_allowed_fields)
- search_objects.append(reduce(operator.or_, q_map))
- search_object = reduce(operator.and_, search_objects)
+ search_objects.append(functools.reduce(operator.or_, q_map))
+ search_object = functools.reduce(operator.and_, search_objects)
queryset = queryset.filter(search_object)
return queryset