From 4f088ec5c18f114f31253894f14a64400544cff5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michael=20Elsd=C3=B6rfer?= Date: Thu, 19 Jun 2008 16:08:36 +0000 Subject: [PATCH] as promised, reverted (with minor exceptions) the previous changeset --- README | 5 ----- django_tables/columns.py | 6 +----- django_tables/tables.py | 31 ++----------------------------- tests/test_basic.py | 21 +-------------------- tests/test_models.py | 3 --- 5 files changed, 4 insertions(+), 62 deletions(-) diff --git a/README b/README index 6d241e2..38153ea 100644 --- a/README +++ b/README @@ -190,11 +190,6 @@ verbose_name, default, visible, sortable Setting ``sortable`` to False will result in this column being unusable in ordering. - The ``choices`` argument currently expects a boolean value (defaults to - False). If enabled, the column will be able to hold an id/value pair. - more extensive choices support (mapping an id to predefined value) is - forthcoming. - ``django_tables.columns`` currently defines three classes, ``Column``, ``TextColumn`` and ``NumberColumn``. However, the two subclasses currently don't do anything special at all, so you can simply use the base class. diff --git a/django_tables/columns.py b/django_tables/columns.py index 2da8cac..6ea137b 100644 --- a/django_tables/columns.py +++ b/django_tables/columns.py @@ -25,16 +25,12 @@ class Column(object): Setting ``sortable`` to False will result in this column being unusable in ordering. - - The ``choices`` argument currently expects a boolean value (defaults to - False). If enabled, the column will be able to hold an id/value pair. """ # Tracks each time a Column instance is created. Used to retain order. creation_counter = 0 def __init__(self, verbose_name=None, name=None, default=None, - visible=True, inaccessible=False, sortable=True, - choices=None): + visible=True, inaccessible=False, sortable=True): self.verbose_name = verbose_name self.name = name self.default = default diff --git a/django_tables/tables.py b/django_tables/tables.py index 44f6043..aa09803 100644 --- a/django_tables/tables.py +++ b/django_tables/tables.py @@ -357,8 +357,7 @@ class BoundRow(object): def __getitem__(self, name): """Returns this row's value for a column. All other access methods, e.g. __iter__, lead ultimately to this.""" - column = self.table.columns[name] - return RowValue(self.data[column.declared_name], column) + return self.data[self.table.columns[name].declared_name] def __contains__(self, item): """Check by both row object and column name.""" @@ -373,30 +372,4 @@ class BoundRow(object): values = property(_get_values) def as_html(self): - pass - -class RowValue(StrAndUnicode): - """Very basic wrapper around a single row value of a column. - - Instead of returning the row values directly, ``BoundRow`` spawns - instances of this class. That's necessary since the ``choices`` - feature means that a single row value can consist of both the value - itself and an associated ID. - """ - def __init__(self, value, column): - if column.column.choices == True: - if isinstance(value, dict): - self.id = value.get('id') - self.value = value.get('value') - elif isinstance(value, (tuple,list,)): - self.id = value[0] - self.value = value[1] - else: - self.id = None - self.value = value - else: - self.id = None - self.value = value - - def __unicode__(self): - return unicode(self.value) \ No newline at end of file + pass \ No newline at end of file diff --git a/tests/test_basic.py b/tests/test_basic.py index a1ffd9f..a3b8295 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -121,23 +121,4 @@ def test_sort(): books.base_columns['language'].sortable = False books.order_by = 'language' assert not books.order_by - test_order(('language', 'num_pages'), [1,3,2,4]) # as if: 'num_pages' - -def test_choices(): - # unrestricted choices - class BookTable(tables.Table): - id = tables.Column() - name = tables.Column() - author = tables.Column(choices=True) - - books = BookTable([ - {'id': 1, 'name': 'A'}, - {'id': 2, 'author': (99, 'Mr. Vanderlay'), 'name': 'B'}, - {'id': 3, 'author': 'Mr. Vanderlay', 'name': 'C'}, - {'id': 4, 'author': {'id': 99, 'value': 'Mr. Vanderlay'}, 'name': 'D'}, - ]) - - assert [r['author'].id for r in books.rows] == [None, 99, None, 99] - assert [r['author'].value for r in books.rows] == [None, 'Mr. Vanderlay', 'Mr. Vanderlay', 'Mr. Vanderlay'] - - # TODO: restricted choices (planned) \ No newline at end of file + test_order(('language', 'num_pages'), [1,3,2,4]) # as if: 'num_pages' \ No newline at end of file diff --git a/tests/test_models.py b/tests/test_models.py index ffe8eb7..1f01d83 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -152,9 +152,6 @@ def test_sort(): countries.order_by = ('custom1', 'custom2') assert countries.order_by == () -def test_choices(): - pass # TODO - def test_pagination(): pass -- 2.26.2