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
9a504efd
Commit
9a504efd
authored
May 12, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic formatting for admin cells
parent
995aa475
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
8 deletions
+29
-8
rest_framework/renderers.py
+2
-2
rest_framework/templates/rest_framework/admin.html
+2
-4
rest_framework/templates/rest_framework/admin/detail.html
+2
-1
rest_framework/templates/rest_framework/admin/list.html
+2
-1
rest_framework/templatetags/rest_framework.py
+21
-0
No files found.
rest_framework/renderers.py
View file @
9a504efd
...
...
@@ -687,7 +687,7 @@ class AdminRenderer(BrowsableAPIRenderer):
results
=
data
if
isinstance
(
results
,
list
):
header
=
results
[
0
]
header
=
results
[
0
]
if
results
else
{}
style
=
'list'
else
:
header
=
results
...
...
@@ -695,7 +695,7 @@ class AdminRenderer(BrowsableAPIRenderer):
columns
=
[
key
for
key
in
header
.
keys
()
if
key
!=
'url'
]
details
=
[
key
for
key
in
header
.
keys
()
if
key
!=
'url'
]
linked
=
[
columns
[
0
]]
linked
=
[
columns
[
0
]]
if
columns
else
[]
context
[
'style'
]
=
style
context
[
'columns'
]
=
columns
...
...
rest_framework/templates/rest_framework/admin.html
View file @
9a504efd
...
...
@@ -73,11 +73,9 @@
<form
id=
"get-form"
class=
"pull-right"
>
<fieldset>
<div
class=
"btn-group format-selection"
>
<a
class=
"btn btn-primary js-tooltip"
href=
'{{ request.get_full_path }}'
rel=
"nofollow"
title=
"Make a GET request on the {{ name }} resource"
>
Format
</a>
<a
class=
"btn btn-primary"
href=
'{{ request.get_full_path }}'
>
Format
</a>
<button
class=
"btn btn-primary dropdown-toggle js-tooltip"
data-toggle=
"dropdown"
title=
"Specify a format for the GET request"
>
<button
class=
"btn btn-primary dropdown-toggle"
data-toggle=
"dropdown"
>
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
>
...
...
rest_framework/templates/rest_framework/admin/detail.html
View file @
9a504efd
{% load rest_framework %}
<table
class=
"table table-striped"
>
<tbody>
{% for key, value in results.items %}
{% if key in details %}
<tr><th>
{{ key|capfirst }}
</th><td>
{{ value }}
</td></tr>
<tr><th>
{{ key|capfirst }}
</th><td>
{{ value
|format_value
}}
</td></tr>
{% endif %}
{% endfor %}
</tbody>
...
...
rest_framework/templates/rest_framework/admin/list.html
View file @
9a504efd
{% load rest_framework %}
<table
class=
"table table-striped"
>
<thead>
<tr>
{% for column in columns%}
<th>
{{ column|capfirst }}
</th>
{% endfor %}
</tr>
...
...
@@ -9,7 +10,7 @@
{% if key in columns %}
<td>
{% if key in linked %}
<a
href=
"{{ row.url }}"
>
{% endif %}
{{ value }}
{{ value
|format_value
}}
{% if key in linked %}
</a>
{% endif %}
</td>
{% endif %}
...
...
rest_framework/templatetags/rest_framework.py
View file @
9a504efd
...
...
@@ -8,6 +8,7 @@ from django.utils.safestring import SafeData, mark_safe
from
django.utils.html
import
smart_urlquote
from
rest_framework.renderers
import
HTMLFormRenderer
from
rest_framework.utils.urls
import
replace_query_param
import
decimal
import
re
register
=
template
.
Library
()
...
...
@@ -104,6 +105,26 @@ def add_class(value, css_class):
return
value
@register.filter
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
''
elif
isinstance
(
value
,
dict
):
return
''
elif
isinstance
(
value
,
six
.
string_types
):
if
(
(
value
.
startswith
(
'http:'
)
or
value
.
startswith
(
'https:'
))
and
not
re
.
search
(
r'\s'
,
value
)
):
return
mark_safe
(
'<a href="{value}">{value}</a>'
.
format
(
value
=
escape
(
value
)))
elif
'@'
in
value
and
not
re
.
search
(
r'\s'
,
value
):
return
mark_safe
(
'<a href="mailto:{value}">{value}</a>'
.
format
(
value
=
escape
(
value
)))
return
six
.
text_type
(
value
)
# Bunch of stuff cloned from urlize
TRAILING_PUNCTUATION
=
[
'.'
,
','
,
':'
,
';'
,
'.)'
,
'"'
,
"']"
,
"'}"
,
"'"
]
WRAPPING_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