This commit is contained in:
Alex Kahan 2016-10-31 16:41:54 -04:00 committed by Tom Christie
parent 46f837a9d1
commit 895c67c9a2
2 changed files with 73 additions and 13 deletions

View File

@ -0,0 +1,11 @@
{% load rest_framework %}
<table class="table table-striped">
<tbody>
{% for key, value in value.items %}
<tr>
<th>{{ key|format_value }}</th>
<td>{{ value|format_value }}</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@ -41,6 +41,9 @@ class TemplateTagTests(TestCase):
self.assertEqual(format_value(None), '<code>null</code>') self.assertEqual(format_value(None), '<code>null</code>')
def test_format_value_hyperlink(self): def test_format_value_hyperlink(self):
"""
Tests format_value with a URL
"""
url = 'http://url.com' url = 'http://url.com'
name = 'name_of_url' name = 'name_of_url'
hyperlink = Hyperlink(url, name) hyperlink = Hyperlink(url, name)
@ -54,6 +57,25 @@ class TemplateTagTests(TestCase):
self.assertEqual(format_value(list_items), '\n item1, item2, item3\n') self.assertEqual(format_value(list_items), '\n item1, item2, item3\n')
self.assertEqual(format_value([]), '\n\n') self.assertEqual(format_value([]), '\n\n')
def test_format_value_dict(self):
"""
Tests format_value with a dict
"""
test_dict = {'a': 'b'}
expected_dict_format = """
<table class="table table-striped">
<tbody>
<tr>
<th>a</th>
<td>b</td>
</tr>
</tbody>
</table>"""
self.assertEqual(
format_html(format_value(test_dict)),
format_html(expected_dict_format)
)
def test_format_value_table(self): def test_format_value_table(self):
""" """
Tests format_value with a list of lists/dicts Tests format_value with a list of lists/dicts
@ -86,15 +108,42 @@ class TemplateTagTests(TestCase):
<tbody> <tbody>
<tr> <tr>
<th>0</th> <th>0</th>
<td></td> <td>
<tableclass="tabletable-striped">
<tbody>
<tr>
<th>item1</th>
<td>value1</td>
</tr>
</tbody>
</table>
</td>
</tr> </tr>
<tr> <tr>
<th>1</th> <th>1</th>
<td></td> <td>
<tableclass="tabletable-striped">
<tbody>
<tr>
<th>item2</th>
<td>value2</td>
</tr>
</tbody>
</table>
</td>
</tr> </tr>
<tr> <tr>
<th>2</th> <th>2</th>
<td></td> <td>
<tableclass="tabletable-striped">
<tbody>
<tr>
<th>item3</th>
<td>value3</td>
</tr>
</tbody>
</table>
</td>
</tr> </tr>
</tbody> </tbody>
</table>""" </table>"""