mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
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>
This commit is contained in:
parent
773a6475af
commit
087b4cd06a
|
@ -1,4 +1,5 @@
|
||||||
import operator
|
import operator
|
||||||
|
import functools
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
def _verify_parameters(g, mandatory_parameters):
|
def _verify_parameters(g, mandatory_parameters):
|
||||||
|
@ -28,9 +29,9 @@ DESCENDING = "-"
|
||||||
|
|
||||||
def __get_q_for_val(name, value):
|
def __get_q_for_val(name, value):
|
||||||
if "OR" in 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:
|
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"):
|
if value.startswith("NOT"):
|
||||||
kwargs = { name : value.strip("NOT") }
|
kwargs = { name : value.strip("NOT") }
|
||||||
return ~Q(**kwargs)
|
return ~Q(**kwargs)
|
||||||
|
@ -45,7 +46,7 @@ def _get_filtering_query(filter_string):
|
||||||
values = search_terms[1].split(VALUE_SEPARATOR)
|
values = search_terms[1].split(VALUE_SEPARATOR)
|
||||||
|
|
||||||
querydict = dict(zip(keys, values))
|
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
|
# we check that the input comes in a valid form that we can recognize
|
||||||
def _validate_input(input, model):
|
def _validate_input(input, model):
|
||||||
|
@ -68,7 +69,7 @@ def _validate_input(input, model):
|
||||||
# Check we are looking for a valid field
|
# Check we are looking for a valid field
|
||||||
valid_fields = model._meta.get_all_field_names()
|
valid_fields = model._meta.get_all_field_names()
|
||||||
for field in input_list[0].split(VALUE_SEPARATOR):
|
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 None, (field, [ x for x in valid_fields ])
|
||||||
|
|
||||||
return input, invalid
|
return input, invalid
|
||||||
|
@ -81,8 +82,8 @@ def _get_search_results(search_term, queryset, model):
|
||||||
q_map = map(lambda x: Q(**{x+'__icontains': st}),
|
q_map = map(lambda x: Q(**{x+'__icontains': st}),
|
||||||
model.search_allowed_fields)
|
model.search_allowed_fields)
|
||||||
|
|
||||||
search_objects.append(reduce(operator.or_, q_map))
|
search_objects.append(functools.reduce(operator.or_, q_map))
|
||||||
search_object = reduce(operator.and_, search_objects)
|
search_object = functools.reduce(operator.and_, search_objects)
|
||||||
queryset = queryset.filter(search_object)
|
queryset = queryset.filter(search_object)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
Loading…
Reference in New Issue
Block a user