def common_photo_upload(request, success="/", nick=None):
  if not nick:
    nick = request.user.nick
  if request.FILES:
    try:
      # we're going to handle a file upload, wee
      validate.nonce(request, 'change_photo')
      img = request.FILES.get('imgfile')

      if not img:
        raise exception.ValidationError('imgfile must be set')
      validate.avatar_photo_size(img)

      img_url = api.avatar_upload(request.user,
                                  nick,
                                  img.read())
      api.avatar_set_actor(request.user, nick, img_url)
      return util.RedirectFlash(success, "Avatar uploaded")
    except:
      exception.handle_exception(request)

  elif 'avatar' in request.POST:
    try:
      validate.nonce(request, 'change_photo')
      avatar_path = request.POST.get('avatar')
      if not avatar_path:
        raise exception.ValidationError('avatar must be set')

      rv = api.avatar_set_actor(request.user, nick, avatar_path)
      if not rv:
        raise exception.ValidationError('failed to set avatar')
      return util.RedirectFlash(success, "Avatar changed")
    except:
      exception.handle_exception(request)

  if request.REQUEST in 'delete':
    try:
      validate.nonce(request, 'delete_photo')
      validate.confirm_dangerous(request, 'Delete your photo?')
      rv = api.avatar_clear_actor(request.user, nick)
      return util.RedirectFlash(success, "Avatar deleted")
    except:
      exception.handle_exception(request)
dataset/ETHPy150Open CollabQ/CollabQ/common/views.py/common_photo_upload/swapped operands of `in`