Commit aa016b84 authored by Mikaël Salson's avatar Mikaël Salson Committed by Vidjil Team
Browse files

vidjil_utils: prevent_none

Utility function to prevent from having a None value.
This can be useful when giving values from the DB to
functions that only expect defined values (eg. when sorting)
parent b12531e4
......@@ -129,6 +129,19 @@ def safe_encoding(string):
except UnicodeDecodeError:
return string
def prevent_none(value, replacement_value):
Return value if it is not None otherwise
>>> prevent_none(None, 2)
>>> prevent_none('toto', 2)
if value is not None:
return value
return replacement_value
# take a list of strings to check and a filter_str (list of word to find (or not))
# return true if the string respect the filter list
Supports Markdown
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