I need do modify data incoming to Form before cleaning. I made it work, but It looks awful:
def __init__(self, *args, **kwargs):
if len(args) > 0:
data = args[0]
elif 'data' in kwargs:
data = kwargs['data']
else:
data = None
if data is not None:
data['content'] = ' '.join(data['content'].strip().split())
super(TagForm, self).__init__(*args, **kwargs)
Is there some laconic solution?
You can compress the
if/elif/elseonto one line easily enough:if argsworks as well asif len(args) > 0becauselength == 0items areFalseandlength > 0items areTrue.if dataworks as well asif data is not Nonebecause you’re assuming thatdatahas at least one key if it’snot Noneanyway, and if it has a key it’sTrue.