From: Michael Elsdoerfer Date: Fri, 27 Jun 2008 23:01:52 +0000 (+0200) Subject: Table.__getitem__ did not work at all X-Git-Tag: 0.2~52 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d75ed67a230c3286589fcfa64e6fe454015fe851;p=django-tables2.git Table.__getitem__ did not work at all --- 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()