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
4c1597ef
Commit
4c1597ef
authored
Jul 23, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error modals
parent
b9962664
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
3 deletions
+45
-3
rest_framework/renderers.py
+16
-3
rest_framework/static/rest_framework/js/default.js
+4
-0
rest_framework/templates/rest_framework/admin.html
+25
-0
No files found.
rest_framework/renderers.py
View file @
4c1597ef
...
...
@@ -683,15 +683,26 @@ class AdminRenderer(BrowsableAPIRenderer):
self
.
accepted_media_type
=
accepted_media_type
or
''
self
.
renderer_context
=
renderer_context
or
{}
response
=
renderer_context
[
'response'
]
request
=
renderer_context
[
'request'
]
view
=
self
.
renderer_context
[
'view'
]
if
response
.
status_code
==
status
.
HTTP_400_BAD_REQUEST
:
# Errors still need to display the list or detail information.
# The only way we can get at that is to simulate a GET request.
self
.
error_form
=
self
.
get_rendered_html_form
(
data
,
view
,
request
.
method
,
request
)
self
.
error_title
=
{
'POST'
:
'Create'
,
'PUT'
:
'Edit'
}
.
get
(
request
.
method
,
'Errors'
)
with
override_method
(
view
,
request
,
'GET'
)
as
request
:
response
=
view
.
get
(
request
,
*
view
.
args
,
**
view
.
kwargs
)
data
=
response
.
data
template
=
loader
.
get_template
(
self
.
template
)
context
=
self
.
get_context
(
data
,
accepted_media_type
,
renderer_context
)
context
=
RequestContext
(
renderer_context
[
'request'
],
context
)
ret
=
template
.
render
(
context
)
# Creation and deletion should use redirects in the admin style.
response
=
renderer_context
[
'response'
]
request
=
renderer_context
[
'request'
]
if
(
response
.
status_code
==
status
.
HTTP_201_CREATED
)
and
(
'Location'
in
response
):
response
.
status_code
=
status
.
HTTP_302_FOUND
ret
=
''
...
...
@@ -742,6 +753,8 @@ class AdminRenderer(BrowsableAPIRenderer):
context
[
'columns'
]
=
columns
context
[
'details'
]
=
details
context
[
'results'
]
=
results
context
[
'error_form'
]
=
getattr
(
self
,
'error_form'
,
None
)
context
[
'error_title'
]
=
getattr
(
self
,
'error_title'
,
None
)
return
context
...
...
rest_framework/static/rest_framework/js/default.js
View file @
4c1597ef
...
...
@@ -59,3 +59,7 @@ if (selectedTab && selectedTab.length > 0) {
// If no tab selected, display rightmost tab.
$
(
'.form-switcher a:first'
).
tab
(
'show'
);
}
$
(
window
).
load
(
function
(){
$
(
'#errorModal'
).
modal
(
'show'
);
});
rest_framework/templates/rest_framework/admin.html
View file @
4c1597ef
...
...
@@ -196,6 +196,31 @@
</div>
</div>
{% if error_form %}
<!-- Errors Modal -->
<div
class=
"modal"
id=
"errorModal"
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"
>
{{ error_title }}
</h4>
</div>
<form
action=
"{{ request.get_full_path }}"
method=
"POST"
enctype=
"multipart/form-data"
class=
"form-horizontal"
novalidate
>
<div
class=
"modal-body"
>
<fieldset>
{{ error_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=
"{{ request.method }}"
type=
"submit"
class=
"btn btn-primary"
>
Save
</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
{% 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>
...
...
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