1 from django.template import loader, RequestContext |
1 from django.template import loader, RequestContext |
2 from django.http import Http404, HttpResponse |
2 from django.http import Http404, HttpResponse |
3 from django.core.xheaders import populate_xheaders |
3 from django.core.xheaders import populate_xheaders |
4 from django.core.paginator import QuerySetPaginator, InvalidPage |
4 from django.core.paginator import Paginator, InvalidPage |
5 from django.core.exceptions import ObjectDoesNotExist |
5 from django.core.exceptions import ObjectDoesNotExist |
6 |
6 |
7 def object_list(request, queryset, paginate_by=None, page=None, |
7 def object_list(request, queryset, paginate_by=None, page=None, |
8 allow_empty=True, template_name=None, template_loader=loader, |
8 allow_empty=True, template_name=None, template_loader=loader, |
9 extra_context=None, context_processors=None, template_object_name='object', |
9 extra_context=None, context_processors=None, template_object_name='object', |
43 A list of the page numbers (1-indexed). |
43 A list of the page numbers (1-indexed). |
44 """ |
44 """ |
45 if extra_context is None: extra_context = {} |
45 if extra_context is None: extra_context = {} |
46 queryset = queryset._clone() |
46 queryset = queryset._clone() |
47 if paginate_by: |
47 if paginate_by: |
48 paginator = QuerySetPaginator(queryset, paginate_by, allow_empty_first_page=allow_empty) |
48 paginator = Paginator(queryset, paginate_by, allow_empty_first_page=allow_empty) |
49 if not page: |
49 if not page: |
50 page = request.GET.get('page', 1) |
50 page = request.GET.get('page', 1) |
51 try: |
51 try: |
52 page_number = int(page) |
52 page_number = int(page) |
53 except ValueError: |
53 except ValueError: |