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
995aa475
Commit
995aa475
authored
May 12, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First pass templates for admin style
parent
21cb8085
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
281 additions
and
0 deletions
+281
-0
rest_framework/pagination.py
+3
-0
rest_framework/renderers.py
+37
-0
rest_framework/templates/rest_framework/admin.html
+212
-0
rest_framework/templates/rest_framework/admin/detail.html
+9
-0
rest_framework/templates/rest_framework/admin/list.html
+20
-0
No files found.
rest_framework/pagination.py
View file @
995aa475
...
@@ -200,6 +200,9 @@ class BasePagination(object):
...
@@ -200,6 +200,9 @@ class BasePagination(object):
def
to_html
(
self
):
# pragma: no cover
def
to_html
(
self
):
# pragma: no cover
raise
NotImplementedError
(
'to_html() must be implemented to display page controls.'
)
raise
NotImplementedError
(
'to_html() must be implemented to display page controls.'
)
def
get_results
(
self
,
data
):
return
data
[
'results'
]
class
PageNumberPagination
(
BasePagination
):
class
PageNumberPagination
(
BasePagination
):
"""
"""
...
...
rest_framework/renderers.py
View file @
995aa475
...
@@ -668,6 +668,43 @@ class BrowsableAPIRenderer(BaseRenderer):
...
@@ -668,6 +668,43 @@ class BrowsableAPIRenderer(BaseRenderer):
return
ret
return
ret
class
AdminRenderer
(
BrowsableAPIRenderer
):
template
=
'rest_framework/admin.html'
format
=
'admin'
def
get_context
(
self
,
data
,
accepted_media_type
,
renderer_context
):
"""
Render the HTML for the browsable API representation.
"""
context
=
super
(
AdminRenderer
,
self
)
.
get_context
(
data
,
accepted_media_type
,
renderer_context
)
paginator
=
getattr
(
context
[
'view'
],
'paginator'
,
None
)
try
:
results
=
data
if
paginator
is
None
else
paginator
.
get_results
(
data
)
except
KeyError
:
results
=
data
if
isinstance
(
results
,
list
):
header
=
results
[
0
]
style
=
'list'
else
:
header
=
results
style
=
'detail'
columns
=
[
key
for
key
in
header
.
keys
()
if
key
!=
'url'
]
details
=
[
key
for
key
in
header
.
keys
()
if
key
!=
'url'
]
linked
=
[
columns
[
0
]]
context
[
'style'
]
=
style
context
[
'columns'
]
=
columns
context
[
'details'
]
=
details
context
[
'linked'
]
=
linked
context
[
'results'
]
=
results
return
context
class
MultiPartRenderer
(
BaseRenderer
):
class
MultiPartRenderer
(
BaseRenderer
):
media_type
=
'multipart/form-data; boundary=BoUnDaRyStRiNg'
media_type
=
'multipart/form-data; boundary=BoUnDaRyStRiNg'
format
=
'multipart'
format
=
'multipart'
...
...
rest_framework/templates/rest_framework/admin.html
0 → 100644
View file @
995aa475
{% load url from future %}
{% load staticfiles %}
{% load rest_framework %}
<!DOCTYPE html>
<html>
<head>
{% block head %}
{% block meta %}
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<meta
name=
"robots"
content=
"NONE,NOARCHIVE"
/>
{% endblock %}
<title>
{% block title %}Django REST framework{% endblock %}
</title>
{% block style %}
{% block bootstrap_theme %}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
rest_framework
/
css
/
bootstrap
.
min
.
css
"
%}"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
rest_framework
/
css
/
bootstrap-tweaks
.
css
"
%}"
/>
{% endblock %}
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
rest_framework
/
css
/
prettify
.
css
"
%}"
/>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"{% static "
rest_framework
/
css
/
default
.
css
"
%}"
/>
{% endblock %}
{% endblock %}
</head>
{% block body %}
<body
class=
"{% block bodyclass %}{% endblock %}"
>
<div
class=
"wrapper"
>
{% block navbar %}
<div
class=
"navbar navbar-static-top {% block bootstrap_navbar_variant %}navbar-inverse{% endblock %}"
>
<div
class=
"container"
>
<span>
{% block branding %}
<a
class=
'navbar-brand'
rel=
"nofollow"
href=
'http://www.django-rest-framework.org'
>
Django REST framework
<span
class=
"version"
>
{{ version }}
</span>
</a>
{% endblock %}
</span>
<ul
class=
"nav navbar-nav pull-right"
>
{% block userlinks %}
{% if user.is_authenticated %}
{% optional_logout request user %}
{% else %}
{% optional_login request %}
{% endif %}
{% endblock %}
</ul>
</div>
</div>
{% endblock %}
<div
class=
"container"
>
{% block breadcrumbs %}
<ul
class=
"breadcrumb"
>
{% for breadcrumb_name, breadcrumb_url in breadcrumblist %}
{% if forloop.last %}
<li
class=
"active"
><a
href=
"{{ breadcrumb_url }}"
>
{{ breadcrumb_name }}
</a></li>
{% else %}
<li><a
href=
"{{ breadcrumb_url }}"
>
{{ breadcrumb_name }}
</a></li>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
<!-- Content -->
<div
id=
"content"
>
{% if 'GET' in allowed_methods %}
<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>
<button
class=
"btn btn-primary dropdown-toggle js-tooltip"
data-toggle=
"dropdown"
title=
"Specify a format for the GET request"
>
<span
class=
"caret"
></span>
</button>
<ul
class=
"dropdown-menu"
>
{% for format in available_formats %}
<li>
<a
class=
"js-tooltip format-option"
href=
'{% add_query_param request api_settings.URL_FORMAT_OVERRIDE format %}'
rel=
"nofollow"
title=
"Make a GET request on the {{ name }} resource with the format set to `{{ format }}`"
>
{{ format }}
</a>
</li>
{% endfor %}
</ul>
</div>
</fieldset>
</form>
{% endif %}
{% if post_form %}
<button
type=
"button"
class=
"button-form btn btn-primary"
data-toggle=
"modal"
data-target=
"#createModal"
>
<span
class=
"glyphicon glyphicon-plus"
aria-hidden=
"true"
></span>
Create
</button>
{% endif %}
{% if put_form %}
<button
type=
"button"
class=
"button-form btn btn-primary"
data-toggle=
"modal"
data-target=
"#editModal"
>
<span
class=
"glyphicon glyphicon-pencil"
aria-hidden=
"true"
></span>
Edit
</button>
{% endif %}
{% if delete_form %}
<form
class=
"button-form"
action=
"{{ request.get_full_path }}"
method=
"POST"
>
{% csrf_token %}
<input
type=
"hidden"
name=
"{{ api_settings.FORM_METHOD_OVERRIDE }}"
value=
"DELETE"
/>
<button
class=
"btn btn-danger"
>
<span
class=
"glyphicon glyphicon-remove"
aria-hidden=
"true"
></span>
Delete
</button>
</form>
{% endif %}
<div
class=
"content-main"
>
<div
class=
"page-header"
>
<h1>
{{ name }}
</h1>
</div>
<div
style=
"float:left"
>
{% block description %}
{{ description }}
{% endblock %}
</div>
{% if paginator %}
<nav
style=
"float: right"
>
{% get_pagination_html paginator %}
</nav>
{% endif %}
<div
class=
"request-info"
style=
"clear: both"
>
{% if style == 'list' %}
{% include "rest_framework/admin/list.html" %}
{% else %}
{% include "rest_framework/admin/detail.html" %}
{% endif %}
</div>
{% if paginator %}
<nav
style=
"float: right"
>
{% get_pagination_html paginator %}
</nav>
{% endif %}
</div>
</div>
<!-- END Content -->
</div>
<!-- /.container -->
</div>
<!-- ./wrapper -->
<!-- Create Modal -->
<div
class=
"modal fade"
id=
"createModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
<h4
class=
"modal-title"
id=
"myModalLabel"
>
Create
</h4>
</div>
<form
action=
"{{ request.get_full_path }}"
method=
"POST"
enctype=
"multipart/form-data"
class=
"form-horizontal"
novalidate
>
<div
class=
"modal-body"
>
<fieldset>
{{ post_form }}
</fieldset>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
<button
type=
"submit"
class=
"btn btn-primary"
>
Save
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit Modal -->
<div
class=
"modal fade"
id=
"editModal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
><span
aria-hidden=
"true"
>
×
</span></button>
<h4
class=
"modal-title"
id=
"myModalLabel"
>
Edit
</h4>
</div>
<form
action=
"{{ request.get_full_path }}"
method=
"POST"
enctype=
"multipart/form-data"
class=
"form-horizontal"
novalidate
>
<div
class=
"modal-body"
>
<fieldset>
{{ put_form }}
</fieldset>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
Close
</button>
<button
name=
"{{ api_settings.FORM_METHOD_OVERRIDE }}"
value=
"PUT"
type=
"submit"
class=
"btn btn-primary"
>
Save
</button>
</div>
</form>
</div>
</div>
</div>
{% block script %}
<script
src=
"{% static "
rest_framework
/
js
/
jquery-1
.
8
.
1-min
.
js
"
%}"
></script>
<script
src=
"{% static "
rest_framework
/
js
/
bootstrap
.
min
.
js
"
%}"
></script>
<script
src=
"{% static "
rest_framework
/
js
/
prettify-min
.
js
"
%}"
></script>
<script
src=
"{% static "
rest_framework
/
js
/
default
.
js
"
%}"
></script>
{% endblock %}
</body>
{% endblock %}
</html>
rest_framework/templates/rest_framework/admin/detail.html
0 → 100644
View file @
995aa475
<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>
{% endif %}
{% endfor %}
</tbody>
</table>
rest_framework/templates/rest_framework/admin/list.html
0 → 100644
View file @
995aa475
<table
class=
"table table-striped"
>
<thead>
<tr>
{% for column in columns%}
<th>
{{ column|capfirst }}
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in results %}
<tr>
{% for key, value in row.items %}
{% if key in columns %}
<td>
{% if key in linked %}
<a
href=
"{{ row.url }}"
>
{% endif %}
{{ value }}
{% if key in linked %}
</a>
{% endif %}
</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
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