Mix of Python and Django utility functions, classed etc.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
# Erik Stein <code@classlibrary.net>, 2017
|
|
|
|
|
|
|
|
|
|
|
|
def firstof(*args, default=None):
|
|
|
|
"""
|
|
|
|
Returns the first value which is neither empty nor None.
|
|
|
|
|
|
|
|
"""
|
|
|
|
if len(args) == 1:
|
|
|
|
iterable = args[0]
|
|
|
|
else:
|
|
|
|
iterable = args
|
|
|
|
|
|
|
|
for value in iterable:
|
|
|
|
if value:
|
|
|
|
return value
|
|
|
|
return default
|