docs: def dump_viewset(viewset_class, root_folder, folder_fn=lambda i: ".", sample_size=None):
      """
      Dump the contents of a rest-api queryset to a folder structure.
  
      :param viewset_class: A rest-api viewset to iterate through
      :param root_folder: The root folder to write results to.
      :param folder_fn: A function to generate a subfolder name for the instance.
      :param sample_size: Number of items to process, for test purposes.
      :return:
      """
      if os.path.exists(root_folder):
          shutil.rmtree(root_folder)
      os.makedirs(root_folder)
  
      vs = viewset_class()
      vs.request = rf.get('')
  
      serializer_class = vs.get_serializer_class()
      serializer = serializer_class(context={'request': vs.request, 'format': 'json', 'view': vs})
  
      renderer = PrettyJSONRenderer()
  
      bar = progressbar.ProgressBar()
      for instance in bar(vs.get_queryset()[:sample_size]):
          dct = serializer.to_representation(instance)
          content = renderer.render(dct)
          folder = os.path.join(root_folder, folder_fn(instance))
          if not os.path.exists(folder):
              os.makedirs(folder)
          filename = "%s.json" % instance.slug
  
          f = file(os.path.join(folder, filename), 'w')
          f.write(content)
          f.close()