From: Michael Elsdörfer Date: Wed, 18 Jun 2008 12:59:53 +0000 (+0000) Subject: better auto verbose names X-Git-Tag: 0.2~67 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9e4d9b27c1c7e0b71820f6297c2675f9014b52eb;p=django-tables2.git better auto verbose names --- diff --git a/README b/README index e318887..b7813a5 100644 --- a/README +++ b/README @@ -51,7 +51,7 @@ If you pass the table object along into a template, you can do: Which will give you: Country Name - Time Zone + Timezone Note that ``population`` is skipped (as it has ``visible=False``), that the declared verbose name for the ``name`` column is used, and that ``time_zone`` diff --git a/django_tables/tables.py b/django_tables/tables.py index eeecde0..aa09803 100644 --- a/django_tables/tables.py +++ b/django_tables/tables.py @@ -1,6 +1,7 @@ import copy from django.utils.datastructures import SortedDict from django.utils.encoding import StrAndUnicode +from django.utils.text import capfirst from columns import Column __all__ = ('BaseTable', 'Table') @@ -334,7 +335,7 @@ class BoundColumn(StrAndUnicode): values = property(_get_values) def __unicode__(self): - return self.column.verbose_name or self.name + return capfirst(self.column.verbose_name or self.name.replace('_', ' ')) def as_html(self): pass diff --git a/tests/test_models.py b/tests/test_models.py index 9d9f3e4..c58f918 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -160,5 +160,4 @@ def test_pagination(): # TODO: support function column sources both for modeltables (methods on model) and static tables (functions in dict) # TODO: manual base columns change -> update() call (add as example in docstr here) -> rebuild snapshot: is row cache, column cache etc. reset? # TODO: test that boundcolumn.name works with name overrides and without -# TODO: more beautiful auto column names # TODO: throw an exception on invalid order_by \ No newline at end of file diff --git a/tests/test_templates.py b/tests/test_templates.py index e49c168..3b59aeb 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -44,7 +44,7 @@ def test_columns_and_rows(): # column name override, hidden columns assert [c.name for c in countries.columns] == ['name', 'capital', 'population', 'cc'] # verbose_name, and fallback to field name - assert [unicode(c) for c in countries.columns] == ['name', 'capital', 'Population Size', 'Phone Ext.'] + assert [unicode(c) for c in countries.columns] == ['Name', 'Capital', 'Population Size', 'Phone Ext.'] # data yielded by each row matches the defined columns for row in countries.rows: @@ -88,7 +88,7 @@ def test_render(): assert Template("{% for column in countries.columns %}{{ column }}/{{ column.name }} {% endfor %}").\ render(Context({'countries': countries})) == \ - "name/name capital/capital Population Size/population Phone Ext./cc " + "Name/name Capital/capital Population Size/population Phone Ext./cc " assert Template("{% for row in countries %}{% for value in row %}{{ value }} {% endfor %}{% endfor %}").\ render(Context({'countries': countries})) == \