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
a1421cd4
Commit
a1421cd4
authored
May 12, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic formatting for dict and list values
parent
9a504efd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
3 deletions
+33
-3
rest_framework/static/rest_framework/css/default.css
+8
-0
rest_framework/templates/rest_framework/admin/dict_value.html
+0
-0
rest_framework/templates/rest_framework/admin/list.html
+1
-1
rest_framework/templates/rest_framework/admin/list_value.html
+11
-0
rest_framework/templatetags/rest_framework.py
+13
-2
No files found.
rest_framework/static/rest_framework/css/default.css
View file @
a1421cd4
...
...
@@ -33,6 +33,14 @@ h2, h3 {
margin-right
:
1em
;
}
td
.nested
{
padding
:
0
!important
;
}
td
.nested
>
table
{
margin
:
0
;
}
form
select
,
form
input
,
form
textarea
{
width
:
90%
;
}
...
...
rest_framework/templates/rest_framework/admin/dict_value.html
0 → 100644
View file @
a1421cd4
rest_framework/templates/rest_framework/admin/list.html
View file @
a1421cd4
...
...
@@ -8,7 +8,7 @@
<tr>
{% for key, value in row.items %}
{% if key in columns %}
<td>
<td
{{
value
|
add_nested_class
}}
>
{% if key in linked %}
<a
href=
"{{ row.url }}"
>
{% endif %}
{{ value|format_value }}
{% if key in linked %}
</a>
{% endif %}
...
...
rest_framework/templates/rest_framework/admin/list_value.html
0 → 100644
View file @
a1421cd4
{% load rest_framework %}
<table
class=
"table table-striped"
>
<tbody>
{% for item in value %}
<tr>
<th>
{{ forloop.counter0 }}
</th>
<td>
{{ item|format_value }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
rest_framework/templatetags/rest_framework.py
View file @
a1421cd4
from
__future__
import
unicode_literals
,
absolute_import
from
django
import
template
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
from
django.template
import
loader
,
Context
from
django.utils
import
six
from
django.utils.encoding
import
iri_to_uri
,
force_text
from
django.utils.html
import
escape
...
...
@@ -110,9 +111,13 @@ def format_value(value):
if
isinstance
(
value
,
(
int
,
float
,
decimal
.
Decimal
,
bool
,
type
(
None
))):
return
mark_safe
(
'<code>
%
s</code>'
%
value
)
elif
isinstance
(
value
,
list
):
return
''
template
=
loader
.
get_template
(
'rest_framework/admin/list_value.html'
)
context
=
Context
({
'value'
:
value
})
return
template
.
render
(
context
)
elif
isinstance
(
value
,
dict
):
return
''
template
=
loader
.
get_template
(
'rest_framework/admin/dict_value.html'
)
context
=
Context
({
'value'
:
value
})
return
template
.
render
(
context
)
elif
isinstance
(
value
,
six
.
string_types
):
if
(
(
value
.
startswith
(
'http:'
)
or
value
.
startswith
(
'https:'
))
and
not
...
...
@@ -124,6 +129,12 @@ def format_value(value):
return
six
.
text_type
(
value
)
@register.filter
def
add_nested_class
(
value
):
if
isinstance
(
value
,
(
list
,
dict
)):
return
'class=nested'
return
''
# Bunch of stuff cloned from urlize
TRAILING_PUNCTUATION
=
[
'.'
,
','
,
':'
,
';'
,
'.)'
,
'"'
,
"']"
,
"'}"
,
"'"
]
...
...
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