def create_new_user(user_name, password=None, **kwargs):
  try:
    auth_model = import_string(settings.AUTH_USER_MODEL)
  except (ImportError, __HOLE__), e:
    logging.warn("Failed importing auth user model: %s." %
                 settings.AUTH_USER_MODEL)
    return
  if password:
    kwargs['password'] = auth_model.hash_password(password)
  else:
    kwargs['password'] = auth_model.get_unusable_password()
  def txn():
    user = auth_model.get_by_key_name(auth_model.get_key_name(user_name))
    if user:
      raise DuplicateKeyError("An user: %s is already registered." % user_name)
    new_user = auth_model(key_name=auth_model.get_key_name(user_name),
                          user_name=user_name, **kwargs)

    new_user.put()
    return new_user
  return db.run_in_transaction(txn)
dataset/ETHPy150Open IanLewis/kay/kay/auth/__init__.py/create_new_user