aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework
diff options
context:
space:
mode:
authorAlec Perkins2012-09-08 00:40:11 -0400
committerAlec Perkins2012-09-08 00:40:11 -0400
commit4cc3dd3b236d6f5eb17d08648780afb86b1bb9af (patch)
tree938f8d57b8522826fad32c1734c436b84aa37aca /djangorestframework
parent94029acd28d058a0daf748de3cc7be482ceb06b9 (diff)
downloaddjango-rest-framework-4cc3dd3b236d6f5eb17d08648780afb86b1bb9af.tar.bz2
Disable OPTIONS if method isn't allowed
Diffstat (limited to 'djangorestframework')
-rw-r--r--djangorestframework/static/djangorestframework/css/style.css13
-rw-r--r--djangorestframework/templates/djangorestframework/base.html9
2 files changed, 19 insertions, 3 deletions
diff --git a/djangorestframework/static/djangorestframework/css/style.css b/djangorestframework/static/djangorestframework/css/style.css
index 8ab89510..3d6fdbdc 100644
--- a/djangorestframework/static/djangorestframework/css/style.css
+++ b/djangorestframework/static/djangorestframework/css/style.css
@@ -30,4 +30,17 @@ h2, h3 {
.format-option {
font-family: Menlo, Consolas, "Andale Mono", "Lucida Console", monospace;
+}
+
+#options-form {
+ position: relative;
+}
+
+/* To allow tooltips to work on disabled elements */
+.disabled-tooltip-shield {
+ position: absolute;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 0;
} \ No newline at end of file
diff --git a/djangorestframework/templates/djangorestframework/base.html b/djangorestframework/templates/djangorestframework/base.html
index 8f99ae5c..a81c2fb7 100644
--- a/djangorestframework/templates/djangorestframework/base.html
+++ b/djangorestframework/templates/djangorestframework/base.html
@@ -64,11 +64,14 @@
<!-- Content -->
<div id="content">
- {% if 'OPTIONS' in allowed_methods and api_settings.FORM_METHOD_OVERRIDE %}
- <form action="{{ request.get_full_path }}" method="post" class="pull-right">
+ {% if api_settings.FORM_METHOD_OVERRIDE %}
+ <form id="options-form" action="{{ request.get_full_path }}" method="post" class="pull-right">
{% csrf_token %}
<input type="hidden" name="{{ api_settings.FORM_METHOD_OVERRIDE }}" value="OPTIONS" />
- <button class="btn">OPTIONS</button>
+ <button class="btn js-tooltip" {% if 'OPTIONS' in allowed_methods %} title="Do an OPTIONS request on the {{ name }} resource"{% else %} disabled{% endif %}>OPTIONS</button>
+ {% if not 'OPTIONS' in allowed_methods %}
+ <div class="js-tooltip disabled-tooltip-shield" title="OPTIONS request not allowed for resource {{ name }}"></div>
+ {% endif %}
</form>
{% endif %}