Django

Code

Changeset 3071

Show
Ignore:
Timestamp:
06/03/06 17:06:48 (2 years ago)
Author:
adrian
Message:

Fixed #2075 -- Added 'page' parameter to object_list generic view. Thanks, kanashii@kanashii.ca

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/views/generic/list_detail.py

    r3070 r3071  
    55from django.core.exceptions import ObjectDoesNotExist 
    66 
    7 def object_list(request, queryset, paginate_by=None, allow_empty=False, 
    8         template_name=None, template_loader=loader, 
     7def object_list(request, queryset, paginate_by=None, page=None, 
     8        allow_empty=False, template_name=None, template_loader=loader, 
    99        extra_context=None, context_processors=None, template_object_name='object', 
    1010        mimetype=None): 
     
    3939    if paginate_by: 
    4040        paginator = ObjectPaginator(queryset, paginate_by) 
    41         page = request.GET.get('page', 1) 
     41        if not page: 
     42            page = request.GET.get('page', 1) 
    4243        try: 
    4344            page = int(page) 
  • django/trunk/docs/generic_views.txt

    r3039 r3071  
    642642    * ``paginate_by``: An integer specifying how many objects should be 
    643643      displayed per page. If this is given, the view will paginate objects with 
    644       ``paginate_by`` objects per page. The view will expect a ``page`` query 
    645       string (GET) parameter containing a zero-indexed page number. 
     644      ``paginate_by`` objects per page. The view will expect either a ``page`` 
     645      query string parameter (via ``GET``) containing a zero-indexed page 
     646      number, or a ``page`` variable specified in the URLconf. See 
     647      "Notes on pagination" below. 
    646648 
    647649    * ``template_name``: The full name of a template to use in rendering the 
     
    711713    * ``hits``: The total number of objects across *all* pages, not just this 
    712714      page. 
     715 
     716Notes on pagination 
     717~~~~~~~~~~~~~~~~~~~ 
     718 
     719If ``paginate_by`` is specified, Django will paginate the results. You can 
     720specify the page number in the URL in one of two ways: 
     721 
     722    * Use the ``page`` parameter in the URLconf. For example, this is what 
     723      your URLconf might look like:: 
     724 
     725        (r'^objects/page(?P<page>[0-9]+)/$', 'object_list', dict(info_dict)) 
     726 
     727    * Pass the page number via the ``page`` query-string parameter. For 
     728      example, a URL would look like this: 
     729 
     730        /objects/?page=3 
     731 
     732In both cases, ``page`` is 1-based, not 0-based, so the first page would be 
     733represented as page ``1``. 
    713734 
    714735``django.views.generic.list_detail.object_detail``