You can compress if/ elif/ elseon one line quite easily:
def __init__(self, *args, **kwargs):
data = args[0] if args else kwargs.get('data', None)
if data:
data['content'] = ' '.join(data['content'].strip().split())
super(TagForm, self).__init__(*args, **kwargs)
if argsworks the same as if len(args) > 0because the length == 0elements Falseand length > 0elements True.
if dataworks the same as if data is not Nonebecause you assume you datahave at least one key, if it not Noneis anyway, and if it has a key True.
source
share