import copy\r
+from django.http import Http404\r
+from django.core import paginator\r
from django.utils.datastructures import SortedDict\r
from django.utils.encoding import StrAndUnicode\r
from django.utils.text import capfirst\r
def paginate(self, klass, *args, **kwargs):\r
page = kwargs.pop('page', 1)\r
self.paginator = klass(self.rows, *args, **kwargs)\r
- self.page = self.paginator.page(page)\r
+ try:\r
+ self.page = self.paginator.page(page)\r
+ except paginator.InvalidPage, e:\r
+ raise Http404(str(e))\r
\r
\r
class Table(BaseTable):\r
from math import sqrt\r
from nose.tools import assert_raises\r
from django.core.paginator import Paginator\r
+from django.http import Http404\r
import django_tables as tables\r
\r
def test_declaration():\r
assert books.paginator.num_pages == 10\r
assert books.page.has_previous() == False\r
assert books.page.has_next() == True\r
+ # exceptions are converted into 404s\r
+ assert_raises(Http404, books.paginate, Paginator, 10, page=9999)\r
+ assert_raises(Http404, books.paginate, Paginator, 10, page="abc")\r
+ \r
\r
# TODO: all the column stuff might warrant it's own test file\r
def test_columns():\r