Skip to content

Commit

Permalink
Explicitly check if column.verbose_name is not None (fixes #280)
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Dec 29, 2015
1 parent 1f4f9c5 commit 4908818
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# Change log

## unreleased
- Explicitly check if `column.verbose_name` is not None to support empty column headers (fixes #280)

## v1.0.6
- Support for custom text value in LinkColumn (#277 by [@toudi](https://github.com/toudi))
- Refactor LinkColumn.render_link() to not escape twice #279
Expand Down
11 changes: 6 additions & 5 deletions django_tables2/columns/base.py
@@ -1,15 +1,16 @@
# coding: utf-8
from __future__ import absolute_import, unicode_literals

import warnings
from collections import OrderedDict
from itertools import islice
import warnings

from django.db.models.fields import FieldDoesNotExist
from django import VERSION as django_version
import six

from django import VERSION as django_version
from django.db.models.fields import FieldDoesNotExist
from django_tables2.templatetags.django_tables2 import title
from django_tables2.utils import A, AttributeDict, OrderBy, OrderByTuple

from ..utils import python_2_unicode_compatible


Expand Down Expand Up @@ -453,7 +454,7 @@ def verbose_name(self):
person.upper should stop at person]).
"""
# Favor an explicit defined verbose_name
if self.column.verbose_name:
if self.column.verbose_name is not None:
return self.column.verbose_name

# This is our reasonable fallback, should the next section not result
Expand Down
13 changes: 11 additions & 2 deletions tests/columns/test_general.py
Expand Up @@ -2,11 +2,12 @@
# pylint: disable=R0912,E0102
from __future__ import unicode_literals

import django_tables2 as tables
from django.utils.safestring import SafeData, mark_safe
from django.utils.translation import ugettext_lazy
from django.utils.safestring import mark_safe, SafeData

import pytest

import django_tables2 as tables
from ..app.models import Person
from ..utils import parse, warns

Expand Down Expand Up @@ -52,6 +53,14 @@ class PersonTable(tables.Table):
assert isinstance(table.columns["safe"].header, SafeData)


def test_should_support_empty_string_as_explicit_verbose_name():
class SimpleTable(tables.Table):
acronym = tables.Column(verbose_name="")

table = SimpleTable([])
assert table.columns["acronym"].header == ""


@pytest.mark.django_db
def test_handle_verbose_name_of_many2onerel():

Expand Down

0 comments on commit 4908818

Please sign in to comment.