mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-03-19 17:34:13 +03:00
Error modals
This commit is contained in:
parent
b996266431
commit
4c1597efe0
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user