Commit 9f565e2e authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by Vincent A

filters: Add Coalesce

parent 3ac4a043
......@@ -946,6 +946,19 @@ class QueryValue(Filter):
return qs[self.querykey][0]
class Coalesce(MultiFilter):
Returns the first value that is not falsy,
or default if all values are falsy.
def filter(self, values):
for value in values:
if value:
return value
return self.default_or_raise(FilterError('All falsy and no default.'))
def test_CleanText():
# This test works poorly under a doctest, or would be hard to read
assert CleanText().filter(u' coucou  \n\théhé') == u'coucou héhé'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment