@register.filter
def username_or(user, attr):
 if (not settings.ACCOUNTS_NO_USERNAME):
  attr = u'username'
 value = getattr(user, attr)
 if callable(value):
  value = value()
 return value

@ register . filter def username_or ( user , attr ) : if ( not settings . ACCOUNTS_NO_USERNAME ) : attr = u'username' value = getattr ( user , attr ) if callable ( value ) : value = value ( ) return value
returns the users username for display .