Skip to content

Commit

Permalink
Removed redundant try-except around field lookup in BooleanColumn
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Jul 6, 2016
1 parent d77c592 commit b4045ca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions django_tables2/columns/booleancolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@library.register
class BooleanColumn(Column):
"""
'''
A column suitable for rendering boolean data.
Arguments:
Expand All @@ -26,7 +26,7 @@ class BooleanColumn(Column):
available:
- *span* -- adds attributes to the <span> tag
"""
'''
def __init__(self, null=False, yesno='✔,✘', **kwargs):
self.yesno = (yesno.split(',') if isinstance(yesno, six.string_types)
else tuple(yesno))
Expand All @@ -39,13 +39,9 @@ def render(self, value, record, bound_column):
# If that's the case, we need to inverse lookup the value to convert to
# a boolean.
if hasattr(record, '_meta'):
try:
field = bound_column.accessor.get_field(record)

if hasattr(field, 'choices') and field.choices is not None:
value = next(val for val, name in field.choices if name == value)
except:
pass
field = bound_column.accessor.get_field(record)
if hasattr(field, 'choices') and field.choices is not None:
value = next(val for val, name in field.choices if name == value)

value = bool(value)
text = self.yesno[int(not value)]
Expand Down
2 changes: 1 addition & 1 deletion tests/columns/test_booleancolumn.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# coding: utf-8
from __future__ import unicode_literals

import pytest
from django.db import models

import django_tables2 as tables
import pytest

from ..app.models import Occupation, Person
from ..utils import attrs
Expand Down

0 comments on commit b4045ca

Please sign in to comment.