Skip to content

Commit

Permalink
Add show_header option to the table constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed May 4, 2016
1 parent 947fc8f commit 64cc296
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions django_tables2/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ class TableBase(object):
:type: `bool`
.. attribute:: show_footer
If `False`, the table footer will not be rendered, even if come columens
have a footer. (default `True`)
:type: `bool`
.. attribute:: prefix
Expand Down Expand Up @@ -395,7 +401,7 @@ def __init__(self, data, order_by=None, orderable=None, empty_text=None,
exclude=None, attrs=None, row_attrs=None, sequence=None,
prefix=None, order_by_field=None, page_field=None,
per_page_field=None, template=None, default=None, request=None,
show_header=None):
show_header=None, show_footer=True):
super(TableBase, self).__init__()
self.exclude = exclude or ()
self.sequence = sequence
Expand All @@ -414,6 +420,8 @@ def __init__(self, data, order_by=None, orderable=None, empty_text=None,
self.page_field = page_field
self.per_page_field = per_page_field
self.show_header = show_header
self.show_footer = show_footer

# Make a copy so that modifying this will not touch the class
# definition. Note that this is different from forms, where the
# copy is made available in a ``fields`` attribute.
Expand Down Expand Up @@ -477,7 +485,7 @@ def has_footer(self):
Returns True if any of the columns define a ``_footer`` attribute or a
``render_footer()`` method
'''
return any(column.has_footer() for column in self.columns)
return self.show_footer and any(column.has_footer() for column in self.columns)

@property
def attrs(self):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ class Table(tables.Table):
assert '<td>18833000</td>' in html


def test_footer_disable_on_table():
'''
Showing the footer can be disabled using show_footer argument to the Table
constructor
'''
class Table(tables.Table):
name = tables.Column()
country = tables.Column(footer='Total:')

table = Table(MEMORY_DATA, show_footer=False)
assert table.has_footer() is False


def test_footer_column_method():

class SummingColumn(tables.Column):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[pytest]
DJANGO_SETTINGS_MODULE=tests.app.settings
norecursedirs = docs *.egg-info .git example .tox

[tox]
args_are_paths = false
Expand Down

0 comments on commit 64cc296

Please sign in to comment.