Extend generic view object_list to support paginate_by via cookies

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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

More like this

  1. Modelaware json serializer by fivethreeo 6 years, 3 months ago
  2. Pagination/Filtering Alphabetically by zain 4 years, 3 months ago
  3. Pagination shortcut by piratus 4 years, 3 months ago
  4. Paginator Tag for 1.x by HM 4 years, 3 months ago
  5. Admin: return to change_list with filter and pagination applied by fx 2 years, 2 months ago

Comments

(Forgotten your password?)