Opened 15 years ago
Closed 15 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: | no | UI/UX: | no |
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)
Change History (5)
comment:1 by , 15 years ago
| Owner: | changed from to |
|---|
by , 15 years ago
| Attachment: | object_list_paginate_by.diff added |
|---|
by , 15 years ago
| Attachment: | object_list_paginate_by.txt added |
|---|
comment:2 by , 15 years ago
| Has patch: | set |
|---|
comment:3 by , 15 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Function-based generic views were deprecated by the introduction of class-based views in [14254]. Class-based views should solve this problem.
Added a plain text version that trac should hopefully be able to display.