def object_list_with_paginate_by(request, **kwargs):
  is_valid_paginate_by_parameter = True
  try:
    paginate_by = int(request.GET.get('paginate_by', 0))
  except ValueError:
    paginate_by = 0

  if not paginate_by: #don't make it into else!
    is_valid_paginate_by_parameter = False
    try:
      paginate_by = int(request.COOKIES.get('paginate_by', 0))
    except ValueError:
      paginate_by = 0

  if paginate_by: #don't make it into else!
    kwargs['paginate_by'] = paginate_by

  response = object_list(request, **kwargs)

  if is_valid_paginate_by_parameter:
    response.set_cookie('paginate_by', paginate_by)

  return response