Try to make the utils/listop functions return something sensible with empty input.

- Legacy-Id: 233
This commit is contained in:
Henrik Levkowetz 2007-06-05 15:05:31 +00:00
parent 47a88da313
commit 5c9e46027b

View file

@ -3,11 +3,17 @@ import operator
def orl(list):
""" Return the "or" of every element in a list.
Used to generate "or" queries with a list of Q objects. """
if list:
return reduce(operator.__or__, list)
else:
return None
def flattenl(list):
""" Flatten a list one level, e.g., turn
[ ['a'], ['b'], ['c', 'd'] ] into
[ 'a', 'b', 'c', 'd' ]
"""
if list:
return reduce(operator.__concat__, list)
else:
return []