mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Polishing touches to #663
This commit is contained in:
parent
03afaee423
commit
048ef6a039
|
@ -361,7 +361,7 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
form_instance = OnTheFlyForm(data)
|
form_instance = OnTheFlyForm(data)
|
||||||
return form_instance
|
return form_instance
|
||||||
|
|
||||||
def get_generic_content_form(self, media_types):
|
def get_raw_data_form(self, view, method, request, media_types):
|
||||||
"""
|
"""
|
||||||
Returns a form that allows for arbitrary content types to be tunneled
|
Returns a form that allows for arbitrary content types to be tunneled
|
||||||
via standard HTML forms.
|
via standard HTML forms.
|
||||||
|
@ -374,6 +374,11 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
and api_settings.FORM_CONTENTTYPE_OVERRIDE):
|
and api_settings.FORM_CONTENTTYPE_OVERRIDE):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# Check permissions
|
||||||
|
obj = getattr(view, 'object', None)
|
||||||
|
if not self.show_form_for_method(view, method, request, obj):
|
||||||
|
return
|
||||||
|
|
||||||
content_type_field = api_settings.FORM_CONTENTTYPE_OVERRIDE
|
content_type_field = api_settings.FORM_CONTENTTYPE_OVERRIDE
|
||||||
content_field = api_settings.FORM_CONTENT_OVERRIDE
|
content_field = api_settings.FORM_CONTENT_OVERRIDE
|
||||||
choices = [(media_type, media_type) for media_type in media_types]
|
choices = [(media_type, media_type) for media_type in media_types]
|
||||||
|
@ -385,7 +390,7 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
super(GenericContentForm, self).__init__()
|
super(GenericContentForm, self).__init__()
|
||||||
|
|
||||||
self.fields[content_type_field] = forms.ChoiceField(
|
self.fields[content_type_field] = forms.ChoiceField(
|
||||||
label='Content Type',
|
label='Media type',
|
||||||
choices=choices,
|
choices=choices,
|
||||||
initial=initial
|
initial=initial
|
||||||
)
|
)
|
||||||
|
@ -431,7 +436,11 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
patch_form = self.get_form(view, 'PATCH', request)
|
patch_form = self.get_form(view, 'PATCH', request)
|
||||||
delete_form = self.get_form(view, 'DELETE', request)
|
delete_form = self.get_form(view, 'DELETE', request)
|
||||||
options_form = self.get_form(view, 'OPTIONS', request)
|
options_form = self.get_form(view, 'OPTIONS', request)
|
||||||
generic_content_form = self.get_generic_content_form(media_types)
|
|
||||||
|
raw_data_put_form = self.get_raw_data_form(view, 'PUT', request, media_types)
|
||||||
|
raw_data_post_form = self.get_raw_data_form(view, 'POST', request, media_types)
|
||||||
|
raw_data_patch_form = self.get_raw_data_form(view, 'PATCH', request, media_types)
|
||||||
|
raw_data_put_or_patch_form = raw_data_put_form or raw_data_patch_form
|
||||||
|
|
||||||
name = self.get_name(view)
|
name = self.get_name(view)
|
||||||
description = self.get_description(view)
|
description = self.get_description(view)
|
||||||
|
@ -449,12 +458,18 @@ class BrowsableAPIRenderer(BaseRenderer):
|
||||||
'breadcrumblist': breadcrumb_list,
|
'breadcrumblist': breadcrumb_list,
|
||||||
'allowed_methods': view.allowed_methods,
|
'allowed_methods': view.allowed_methods,
|
||||||
'available_formats': [renderer.format for renderer in view.renderer_classes],
|
'available_formats': [renderer.format for renderer in view.renderer_classes],
|
||||||
|
|
||||||
'put_form': put_form,
|
'put_form': put_form,
|
||||||
'post_form': post_form,
|
'post_form': post_form,
|
||||||
'patch_form': patch_form,
|
'patch_form': patch_form,
|
||||||
'delete_form': delete_form,
|
'delete_form': delete_form,
|
||||||
'options_form': options_form,
|
'options_form': options_form,
|
||||||
'generic_content_form': generic_content_form,
|
|
||||||
|
'raw_data_put_form': raw_data_put_form,
|
||||||
|
'raw_data_post_form': raw_data_post_form,
|
||||||
|
'raw_data_patch_form': raw_data_patch_form,
|
||||||
|
'raw_data_put_or_patch_form': raw_data_put_or_patch_form,
|
||||||
|
|
||||||
'api_settings': api_settings
|
'api_settings': api_settings
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -154,12 +154,43 @@ html, body {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-content {
|
.well .form-actions {
|
||||||
padding-top: 25px;
|
padding-bottom: 0;
|
||||||
background: #fff;
|
margin-bottom: 0;
|
||||||
border: 1px solid #ddd;
|
}
|
||||||
border-top: none;
|
|
||||||
border-radius: 0 0 4px 4px;
|
.well form {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs {
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs > li {
|
||||||
|
margin-bottom: -3px;
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs li a {
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs > .active > a {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-tabs > .active > a:hover {
|
||||||
|
background: #f5f5f5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-below > .nav-tabs {
|
||||||
|
border-bottom: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-below > .nav-tabs > li {
|
||||||
|
margin-bottom: -2px !important;
|
||||||
|
margin-right: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
#footer, #push {
|
#footer, #push {
|
||||||
|
|
|
@ -123,83 +123,83 @@
|
||||||
|
|
||||||
{% if response.status_code != 403 %}
|
{% if response.status_code != 403 %}
|
||||||
|
|
||||||
{% if post_form %}
|
{% if post_form or raw_data_post_form %}
|
||||||
<div class="well">
|
<div {% if post_form %}class="tabbable"{% endif %}>
|
||||||
|
{% if post_form %}
|
||||||
<ul class="nav nav-tabs form-switcher">
|
<ul class="nav nav-tabs form-switcher">
|
||||||
{% if post_form %}
|
<li><a href="#object-form" data-toggle="tab">HTML form</a></li>
|
||||||
<li><a href="#object-form" data-toggle="tab">HTML</a></li>
|
<li><a href="#generic-content-form" data-toggle="tab">Raw data</a></li>
|
||||||
{% endif %}
|
|
||||||
<li><a href="#generic-content-form" data-toggle="tab">Generic content</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
{% endif %}
|
||||||
|
<div class="well tab-content">
|
||||||
{% if post_form %}
|
{% if post_form %}
|
||||||
<div class="tab-pane" id="object-form">
|
<div class="tab-pane" id="object-form">
|
||||||
{% with form=post_form %}
|
{% with form=post_form %}
|
||||||
<form action="{{ request.get_full_path }}" method="POST" {% if form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
|
<form action="{{ request.get_full_path }}" method="POST" {% if form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
{% include "rest_framework/form.html" %}
|
{% include "rest_framework/form.html" %}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button class="btn btn-primary" title="Make a POST request on the {{ name }} resource">POST</button>
|
<button class="btn btn-primary" title="Make a POST request on the {{ name }} resource">POST</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="tab-pane" id="generic-content-form">
|
<div {% if post_form %}class="tab-pane"{% endif %} id="generic-content-form">
|
||||||
{% with form=generic_content_form %}
|
{% with form=raw_data_post_form %}
|
||||||
<form action="{{ request.get_full_path }}" method="POST" {% if form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
|
<form action="{{ request.get_full_path }}" method="POST" class="form-horizontal">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
{% include "rest_framework/form.html" %}
|
{% include "rest_framework/form.html" %}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button class="btn btn-primary" title="Make a POST request on the {{ name }} resource">POST</button>
|
<button class="btn btn-primary" title="Make a POST request on the {{ name }} resource">POST</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if 'PUT' in allowed_methods or 'PATCH' in allowed_methods %}
|
{% if put_form or raw_data_put_form or raw_data_patch_form %}
|
||||||
<div class="well">
|
<div {% if put_form %}class="tabbable"{% endif %}>
|
||||||
|
{% if put_form %}
|
||||||
<ul class="nav nav-tabs form-switcher">
|
<ul class="nav nav-tabs form-switcher">
|
||||||
{% if put_form %}
|
<li><a href="#object-form" data-toggle="tab">HTML form</a></li>
|
||||||
<li><a href="#object-form" data-toggle="tab">HTML</a></li>
|
<li><a href="#generic-content-form" data-toggle="tab">Raw data</a></li>
|
||||||
{% endif %}
|
|
||||||
<li><a href="#generic-content-form" data-toggle="tab">Generic content</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
{% endif %}
|
||||||
|
<div class="well tab-content">
|
||||||
{% if put_form %}
|
{% if put_form %}
|
||||||
<div class="tab-pane" id="object-form">
|
<div class="tab-pane" id="object-form">
|
||||||
{% with form=put_form %}
|
{% with form=put_form %}
|
||||||
<form action="{{ request.get_full_path }}" method="POST" {% if form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
|
<form action="{{ request.get_full_path }}" method="POST" {% if form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
{% include "rest_framework/form.html" %}
|
{% include "rest_framework/form.html" %}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button class="btn btn-primary js-tooltip" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PUT" title="Make a PUT request on the {{ name }} resource">PUT</button>
|
<button class="btn btn-primary js-tooltip" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PUT" title="Make a PUT request on the {{ name }} resource">PUT</button>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="tab-pane" id="generic-content-form">
|
<div {% if put_form %}class="tab-pane"{% endif %} id="generic-content-form">
|
||||||
{% with form=generic_content_form %}
|
{% with form=raw_data_put_or_patch_form %}
|
||||||
<form action="{{ request.get_full_path }}" method="POST" {% if form.is_multipart %}enctype="multipart/form-data"{% endif %} class="form-horizontal">
|
<form action="{{ request.get_full_path }}" method="POST" class="form-horizontal">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
{% include "rest_framework/form.html" %}
|
{% include "rest_framework/form.html" %}
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
{% if 'PUT' in allowed_methods %}
|
{% if raw_data_put_form %}
|
||||||
<button class="btn btn-primary js-tooltip" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PUT" title="Make a PUT request on the {{ name }} resource">PUT</button>
|
<button class="btn btn-primary js-tooltip" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PUT" title="Make a PUT request on the {{ name }} resource">PUT</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if 'PATCH' in allowed_methods %}
|
{% if raw_data_patch_form %}
|
||||||
<button class="btn btn-primary js-tooltip" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PATCH" title="Make a PUT request on the {{ name }} resource">PATCH</button>
|
<button class="btn btn-primary js-tooltip" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="PATCH" title="Make a PUT request on the {{ name }} resource">PATCH</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user