Opened 6 years ago

Closed 6 years ago

#13986 closed (fixed)

When using the object_list you can not pass paginate_by in the url

Reported by: Dougal Matthews Owned by: Dougal Matthews
Component: Generic views Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In trying to vary the page size in the url, we tried to pass in the paginate_by in the url. The Pagination class does not convert arguements into ints and fails.

This is the documented behaviour however the view would be more generic if this could be varied like this.

This can be reproduced by adding the following to your urls.py

urlpatterns += patterns('django.views.generic.list_detail',
    (r'^object_list/(?P<paginate_by>[0-9]?)/page(?P<page>[0-9]+)/$', 'object_list', object_list_dict),
)

A request to this url will cause the following traceback

======================================================================
ERROR: test_finds_past (regressiontests.views.tests.generic.object_list.ObjectDetailTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/dougal/Django/django_src/tests/regressiontests/views/tests/generic/object_list.py", line 17, in test_finds_past
    response = self.client.get('/views/object_list/%s/page1/' % paginate_by)
  File "/Users/dougal/Django/django_src/django/test/client.py", line 290, in get
    response = self.request(**r)
  File "/Users/dougal/Django/django_src/django/core/handlers/base.py", line 100, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/Users/dougal/Django/django_src/django/views/generic/list_detail.py", line 60, in object_list
    page_obj = paginator.page(page_number)
  File "/Users/dougal/Django/django_src/django/core/paginator.py", line 41, in page
    if top + self.orphans >= self.count:
TypeError: coercing to Unicode: need string or buffer, int found

----------------------------------------------------------------------

the object_list generic view already converts the page argument to an int. It would then make sense to convert paginate_by in the same place in the view

Attachments (2)

object_list_paginate_by.diff (4.3 KB) - added by Dougal Matthews 6 years ago.
object_list_paginate_by.txt (4.3 KB) - added by Dougal Matthews 6 years ago.
Added a plain text version that trac should hopefully be able to display.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 6 years ago by Dougal Matthews

Owner: changed from nobody to Dougal Matthews

Changed 6 years ago by Dougal Matthews

Changed 6 years ago by Dougal Matthews

Attachment: object_list_paginate_by.txt added

Added a plain text version that trac should hopefully be able to display.

comment:2 Changed 6 years ago by Dougal Matthews

Has patch: set

I've attached a patch which converts the paginate_by value into an int. This is built on top of a patch added to #13897 (which adds tests for object_list) and thus needs to be applied after the patch in #13897.

I added a .txt version as trac fails to display the diff correctly.

comment:3 Changed 6 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

Function-based generic views were deprecated by the introduction of class-based views in [14254]. Class-based views should solve this problem.

Note: See TracTickets for help on using tickets.
Back to Top