From: Michael Elsdoerfer Date: Sat, 10 Jan 2009 01:13:00 +0000 (+0100) Subject: Fixed a bug that made it hard to change the visibility of a column of a table instance X-Git-Tag: 0.2~34 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ac4d3e870d18084f3be0e405ffe7735bbe10b6f7;p=django-tables2.git Fixed a bug that made it hard to change the visibility of a column of a table instance --- diff --git a/django_tables/tables.py b/django_tables/tables.py index f4fea4f..94274e8 100644 --- a/django_tables/tables.py +++ b/django_tables/tables.py @@ -467,7 +467,7 @@ class Columns(object): This is primarily geared towards table rendering. """ for column in self.all(): - if column.column.visible: + if column.visible: yield column def __contains__(self, item): diff --git a/tests/test_basic.py b/tests/test_basic.py index 51f8972..372532a 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -308,7 +308,7 @@ def test_pagination(): # exceptions are converted into 404s assert_raises(Http404, books.paginate, Paginator, 10, page=9999) assert_raises(Http404, books.paginate, Paginator, 10, page="abc") - + # TODO: all the column stuff might warrant it's own test file def test_columns(): @@ -316,7 +316,7 @@ def test_columns(): """ class BookTable(tables.Table): - id = tables.Column(sortable=False) + id = tables.Column(sortable=False, visible=False) name = tables.Column(sortable=True) pages = tables.Column(sortable=True) language = tables.Column(sortable=False) @@ -324,6 +324,12 @@ def test_columns(): assert list(books.columns.sortable()) == [c for c in books.columns if c.sortable] + # .columns iterator only yields visible columns + assert len(list(books.columns)) == 3 + # visiblity of columns can be changed at instance-time + books.columns['id'].visible = True + assert len(list(books.columns)) == 4 + def test_column_order(): """Test the order functionality of bound columns.