Skip to content

Commit

Permalink
Prevent superfluous space after cssClass (fixes #416)
Browse files Browse the repository at this point in the history
  • Loading branch information
jieter committed Feb 27, 2017
1 parent f8d7c7a commit 2d81ffc
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions tests/test_rows.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# coding: utf-8
import pytest

import django_tables2 as tables

import pytest
from django.db import models


Expand Down Expand Up @@ -58,6 +56,33 @@ class SimpleTable(tables.Table):
assert 'gamma' not in row


def test_row_attrs():
'''
If a callable returns an empty string, do not add a space to the CSS class
attribute. (#416)
'''
from itertools import count
counter = count()

class Table(tables.Table):
name = tables.Column()

class Meta(object):
row_attrs = {
'class': lambda x: '' if next(counter) % 2 == 0 else 'bla'
}

table = Table([
{'name': 'Brian'},
{'name': 'Thomas'},
{'name': 'John'}
])

assert table.rows[0].attrs['class'] == 'even'
assert table.rows[1].attrs['class'] == 'bla odd'
assert table.rows[1].attrs['class'] == 'even'


def test_get_cell_display():

class A(models.Model):
Expand Down

0 comments on commit 2d81ffc

Please sign in to comment.