Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust "null" to expected behavior #521

Merged
merged 2 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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