From: Michael Elsdoerfer Date: Fri, 27 Jun 2008 20:33:11 +0000 (+0200) Subject: adding to a previous fix, make sure order_by is always a fully featured OrderByTuple X-Git-Tag: 0.2~53 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b48d2b387767592527879f85966cc12981837e06;p=django-tables2.git adding to a previous fix, make sure order_by is always a fully featured OrderByTuple --- diff --git a/django_tables/tables.py b/django_tables/tables.py index 9b814fe..064407b 100644 --- a/django_tables/tables.py +++ b/django_tables/tables.py @@ -244,7 +244,7 @@ class BaseTable(object): raise ValueError('Column name %s is invalid.' % o) self._order_by = OrderByTuple(validated_order_by) else: - self._order_by = () + self._order_by = OrderByTuple() order_by = property(lambda s: s._order_by, _set_order_by) def __unicode__(self): diff --git a/tests/test_basic.py b/tests/test_basic.py index a41daf2..b45ffed 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -141,13 +141,17 @@ def test_sort(): books.order_by = order assert [b['id'] for b in books.rows] == result - # None is normalized to an empty tuple, ensuring iterability; it's - # also the default value + # None is normalized to an empty order by tuple, ensuring iterability; + # it also supports all the cool methods that we offer for order_by. + # This is true for the default case... assert books.order_by == () iter(books.order_by) + assert hasattr(books.order_by, 'reverse') + # ...as well as when explicitly set to None. books.order_by = None assert books.order_by == () iter(books.order_by) + assert hasattr(books.order_by, 'reverse') # test various orderings test_order(('num_pages',), [1,3,2,4])