def autocreate_username(candidate, tries=1):
 max_tries = settings.MAX_GEN_USERNAME_TRIES
 from olympia.amo.utils import slugify, SLUG_OK
 make_u = partial(slugify, ok=SLUG_OK, lower=True, spaces=False, delimiter='-')
 adjusted_u = make_u(candidate)
 if (tries > 1):
  adjusted_u = ('%s%s' % (adjusted_u, tries))
 if (DeniedName.blocked(adjusted_u) or (adjusted_u == '') or (tries > max_tries) or (len(adjusted_u) > 255)):
  log.info(('username blocked, empty, max tries reached, or too long; username=%s; max=%s' % (adjusted_u, max_tries)))
  return autocreate_username(uuid.uuid4().hex[0:15])
 if UserProfile.objects.filter(username=adjusted_u).count():
  return autocreate_username(candidate, tries=(tries + 1))
 return adjusted_u

def autocreate_username ( candidate , tries = 1 ) : max_tries = settings . MAX_GEN_USERNAME_TRIES from olympia . amo . utils import slugify , SLUG_OK make_u = partial ( slugify , ok = SLUG_OK , lower = True , spaces = False , delimiter = '-' ) adjusted_u = make_u ( candidate ) if ( tries > 1 ) : adjusted_u = ( '%s%s' % ( adjusted_u , tries ) ) if ( DeniedName . blocked ( adjusted_u ) or ( adjusted_u == '' ) or ( tries > max_tries ) or ( len ( adjusted_u ) > 255 ) ) : log . info ( ( 'username blocked, empty, max tries reached, or too long; username=%s; max=%s' % ( adjusted_u , max_tries ) ) ) return autocreate_username ( uuid . uuid4 ( ) . hex [ 0 : 15 ] ) if UserProfile . objects . filter ( username = adjusted_u ) . count ( ) : return autocreate_username ( candidate , tries = ( tries + 1 ) ) return adjusted_u
returns a unique valid username .