Skip to content

Commit

Permalink
Fix KeyError on combining exclude and sequence (fixes #205)
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Jun 4, 2016
1 parent 84c8c7f commit 7d8f3f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions django_tables2/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ def __new__(mcs, name, bases, attrs):
# Reorder the columns based on explicit sequence
if opts.sequence:
opts.sequence.expand(base_columns.keys())
# Table's sequence defaults to sequence declared in Meta
base_columns = OrderedDict(((x, base_columns[x]) for x in opts.sequence))
# Table's sequence defaults to sequence declared in Meta, if the
# column is not excluded
base_columns = OrderedDict((
(x, base_columns[x]) for x in opts.sequence if x in base_columns
))

# Set localize on columns
for col_name in base_columns.keys():
Expand Down
10 changes: 9 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ class ExcludeTable(UnorderedTable):

class Meta:
exclude = ('beta', )

table = ExcludeTable([])
assert [c.name for c in table.columns] == ['i', 'alpha', 'added']

Expand All @@ -408,10 +409,17 @@ class SimpleTable(tables.Table):


def test_exclude_should_work_on_sequence_too():
'''
It should be possible to define a sequence on a table and excluded
and exclude it in a child of that table.
'''
class PersonTable(tables.Table):
first_name = tables.Column()
last_name = tables.Column()
occupation = tables.Column()

class Meta:
model = Person
fields = ()
sequence = ('first_name', 'last_name', 'occupation')

class AnotherPersonTable(PersonTable):
Expand Down

0 comments on commit 7d8f3f5

Please sign in to comment.