From 54e4728426b2bbdfcd52b720d401f4740dfae050 Mon Sep 17 00:00:00 2001 From: Michael Elsdoerfer Date: Thu, 26 Jun 2008 23:12:12 +0200 Subject: [PATCH] fixed bug when accessing rows by index; added the missing test that caused this to go unnoticed; added some type checking to make certain errors more easier to find --- django_tables/tables.py | 4 +++- tests/test_basic.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django_tables/tables.py b/django_tables/tables.py index 8fab3d7..3a1f532 100644 --- a/django_tables/tables.py +++ b/django_tables/tables.py @@ -448,8 +448,10 @@ class Rows(object): for row in self.table.data[key]: result.append(self.row_klass(self.table, row)) return result + elif isinstance(key, int): + return self.row_klass(self.table, self.table.data[key]) else: - return self.row_klass(self, table, self.table.data[key]) + raise TypeError('Key must be a slice or integer.') class BoundRow(object): """Represents a single row of data, bound to a table. diff --git a/tests/test_basic.py b/tests/test_basic.py index cc6c33d..d090df0 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -82,6 +82,10 @@ def test_basic(): # columns with data= option work fine assert r['email'] == 'foo@bar.org' + # try to splice rows by index + assert 'name' in stuff.rows[0] + assert isinstance(stuff.rows[0:], list) + # 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