models: fix bug in username() when first_name and last_name are not both defined

This commit is contained in:
Benjamin Dauvergne 2013-11-26 10:30:19 +01:00
parent 9a94816476
commit af28eb63f3
1 changed files with 3 additions and 1 deletions

View File

@ -140,7 +140,9 @@ class Content(Model):
def username(user):
'''Return the full name of a user if it has one, the username otherwise.'''
if user.first_name or user.last_name:
return u'{last_name} {first_name}'.format(**user.__dict__)
d = dict(last_name='', first_name='')
d.update(user.__dict__)
return u'{last_name} {first_name}'.format(**d)
return user.username