Skip to content

Commit

Permalink
Adjust "null" to expected behavior (#521)
Browse files Browse the repository at this point in the history
* Adjust "null" to expected behavior

Add "not" to ensure that when null is True (making ` None or '' ` distinct from False) that the default placeholder (--) is rendered
  • Loading branch information
kalzoo authored and jieter committed Mar 8, 2018
1 parent 8cf1687 commit 82d5acb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion django_tables2/columns/booleancolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BooleanColumn(Column):
def __init__(self, null=False, yesno='✔,✘', **kwargs):
self.yesno = (yesno.split(',') if isinstance(yesno, six.string_types)
else tuple(yesno))
if null:
if not null:
kwargs['empty_values'] = ()
super(BooleanColumn, self).__init__(**kwargs)

Expand Down
8 changes: 4 additions & 4 deletions tests/columns/test_booleancolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Meta:

column = Table.base_columns['field']
assert type(column) == tables.BooleanColumn
assert column.empty_values != ()
assert column.empty_values == ()

def test_should_be_used_for_nullbooleanfield(self):
class NullBoolModel(models.Model):
Expand All @@ -39,18 +39,18 @@ class Meta:

column = Table.base_columns['field']
assert type(column) == tables.BooleanColumn
assert column.empty_values == ()
assert column.empty_values != ()

def test_treat_none_different_from_false(self):
class Table(tables.Table):
col = tables.BooleanColumn(null=False, default='---')
col = tables.BooleanColumn(null=True, default='---')

table = Table([{'col': None}])
assert table.rows[0].get_cell('col') == '---'

def test_treat_none_as_false(self):
class Table(tables.Table):
col = tables.BooleanColumn(null=True)
col = tables.BooleanColumn(null=False, default='---')

table = Table([{'col': None}])
assert table.rows[0].get_cell('col') == '<span class="false">✘</span>'
Expand Down

0 comments on commit 82d5acb

Please sign in to comment.