Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
895c67c9
Commit
895c67c9
authored
Oct 31, 2016
by
Alex Kahan
Committed by
Tom Christie
Oct 31, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #4532 (#4636)
parent
46f837a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
13 deletions
+73
-13
rest_framework/templates/rest_framework/admin/dict_value.html
+11
-0
tests/test_templatetags.py
+62
-13
No files found.
rest_framework/templates/rest_framework/admin/dict_value.html
View file @
895c67c9
{% 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>
tests/test_templatetags.py
View file @
895c67c9
...
@@ -41,6 +41,9 @@ class TemplateTagTests(TestCase):
...
@@ -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):
...
@@ -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
...
@@ -84,20 +106,47 @@ class TemplateTagTests(TestCase):
...
@@ -84,20 +106,47 @@ class TemplateTagTests(TestCase):
expected_dict_format
=
"""
expected_dict_format
=
"""
<tableclass="tabletable-striped">
<tableclass="tabletable-striped">
<tbody>
<tbody>
<tr>
<tr>
<th>0</th>
<th>0</th>
<td></td>
<td>
</tr>
<tableclass="tabletable-striped">
<tr>
<tbody>
<th>1</th>
<tr>
<td></td>
<th>item1</th>
</tr>
<td>value1</td>
<tr>
</tr>
<th>2</th>
</tbody>
<td></td>
</table>
</tr>
</td>
</tr>
<tr>
<th>1</th>
<td>
<tableclass="tabletable-striped">
<tbody>
<tr>
<th>item2</th>
<td>value2</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<th>2</th>
<td>
<tableclass="tabletable-striped">
<tbody>
<tr>
<th>item3</th>
<td>value3</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</tbody>
</table>"""
</table>"""
list_of_dicts
=
[{
'item1'
:
'value1'
},
{
'item2'
:
'value2'
},
{
'item3'
:
'value3'
}]
list_of_dicts
=
[{
'item1'
:
'value1'
},
{
'item2'
:
'value2'
},
{
'item3'
:
'value3'
}]
self
.
assertEqual
(
self
.
assertEqual
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment