From d75ed67a230c3286589fcfa64e6fe454015fe851 Mon Sep 17 00:00:00 2001 From: Michael Elsdoerfer Date: Sat, 28 Jun 2008 01:01:52 +0200 Subject: [PATCH] Table.__getitem__ did not work at all --- django_tables/tables.py | 8 ++------ tests/test_basic.py | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/django_tables/tables.py b/django_tables/tables.py index 064407b..21969c3 100644 --- a/django_tables/tables.py +++ b/django_tables/tables.py @@ -254,12 +254,8 @@ class BaseTable(object): for row in self.rows: yield row - def __getitem__(self, name): - try: - column = self.columns[name] - except KeyError: - raise KeyError('Key %r not found in Table' % name) - return BoundColumn(self, column, name) + def __getitem__(self, key): + return self.rows[key] # just to make those readonly columns = property(lambda s: s._columns) diff --git a/tests/test_basic.py b/tests/test_basic.py index b45ffed..5914186 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -86,6 +86,10 @@ def test_basic(): assert 'name' in stuff.rows[0] assert isinstance(stuff.rows[0:], list) + # [bug] splicing the table gives as valid, working rows + assert list(stuff[0]) == list(stuff.rows[0]) + assert stuff[0]['name'] == 'Foo Bar' + # changing an instance's base_columns does not change the class assert id(stuff.base_columns) != id(StuffTable.base_columns) stuff.base_columns['test'] = tables.Column() -- 2.26.2