aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework
diff options
context:
space:
mode:
authorSébastien Piquemal2012-02-14 10:05:28 +0200
committerSébastien Piquemal2012-02-14 10:05:28 +0200
commit821844bb11e5262fb0dfc2fecf2add8fe18d3210 (patch)
tree02c16208ac3f6432746bd79693123dd399282d83 /djangorestframework
parentb33579a7a18c2cbc6e3789d4a7dc78c82fb0fe80 (diff)
downloaddjango-rest-framework-821844bb11e5262fb0dfc2fecf2add8fe18d3210.tar.bz2
fixed examples, corrected small bugs in the process
Diffstat (limited to 'djangorestframework')
-rw-r--r--djangorestframework/renderers.py3
-rw-r--r--djangorestframework/response.py10
-rw-r--r--djangorestframework/templates/renderer.html12
3 files changed, 16 insertions, 9 deletions
diff --git a/djangorestframework/renderers.py b/djangorestframework/renderers.py
index 08022c7c..2cc9cc88 100644
--- a/djangorestframework/renderers.py
+++ b/djangorestframework/renderers.py
@@ -13,7 +13,7 @@ from django.utils import simplejson as json
from djangorestframework.compat import yaml
-from djangorestframework.utils import dict2xml, url_resolves
+from djangorestframework.utils import dict2xml, url_resolves, allowed_methods
from djangorestframework.utils.breadcrumbs import get_breadcrumbs
from djangorestframework.utils.mediatypes import get_media_type_params, add_media_type_param, media_type_matches
from djangorestframework import VERSION
@@ -349,6 +349,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
'name': name,
'version': VERSION,
'breadcrumblist': breadcrumb_list,
+ 'allowed_methods': allowed_methods(self.view),
'available_formats': self.view._rendered_formats,
'put_form': put_form_instance,
'post_form': post_form_instance,
diff --git a/djangorestframework/response.py b/djangorestframework/response.py
index c5fdccbc..6c42c898 100644
--- a/djangorestframework/response.py
+++ b/djangorestframework/response.py
@@ -75,7 +75,7 @@ class Response(SimpleTemplateResponse):
Returns reason text corresponding to our HTTP response status code.
Provided for convenience.
"""
- return STATUS_CODE_TEXT.get(self.status, '')
+ return STATUS_CODE_TEXT.get(self.status_code, '')
def _determine_accept_list(self):
"""
@@ -166,5 +166,11 @@ class ImmediateResponse(Response, BaseException):
"""
A subclass of :class:`Response` used to abort the current request handling.
"""
- pass
+ def __str__(self):
+ """
+ Since this class is also an exception it has to provide a sensible
+ representation for the cases when it is treated as an exception.
+ """
+ return ('%s must be caught in try/except block, '
+ 'and returned as a normal HttpResponse' % self.__class__.__name__)
diff --git a/djangorestframework/templates/renderer.html b/djangorestframework/templates/renderer.html
index 8b5c77c7..808d9664 100644
--- a/djangorestframework/templates/renderer.html
+++ b/djangorestframework/templates/renderer.html
@@ -29,7 +29,7 @@
<div id="content" class="{% block coltype %}colM{% endblock %}">
- {% if 'OPTIONS' in view.allowed_methods %}
+ {% if 'OPTIONS' in allowed_methods %}
<form action="{{ request.get_full_path }}" method="post">
{% csrf_token %}
<input type="hidden" name="{{ METHOD_PARAM }}" value="OPTIONS" />
@@ -42,11 +42,11 @@
<p>{{ description }}</p>
<div class='module'>
<pre><b>{{ response.status_code }} {{ response.status_text }}</b>{% autoescape off %}
-{% for key, val in response.headers.items %}<b>{{ key }}:</b> {{ val|urlize_quoted_links }}
+{% for key, val in response.items %}<b>{{ key }}:</b> {{ val|urlize_quoted_links }}
{% endfor %}
{{ content|urlize_quoted_links }}</pre>{% endautoescape %}</div>
- {% if 'GET' in view.allowed_methods %}
+ {% if 'GET' in allowed_methods %}
<form>
<fieldset class='module aligned'>
<h2>GET {{ name }}</h2>
@@ -65,7 +65,7 @@
{# Only display the POST/PUT/DELETE forms if method tunneling via POST forms is enabled and the user has permissions on this view. #}
{% if METHOD_PARAM and response.status_code != 403 %}
- {% if 'POST' in view.allowed_methods %}
+ {% if 'POST' in allowed_methods %}
<form action="{{ request.get_full_path }}" method="post" {% if post_form.is_multipart %}enctype="multipart/form-data"{% endif %}>
<fieldset class='module aligned'>
<h2>POST {{ name }}</h2>
@@ -86,7 +86,7 @@
</form>
{% endif %}
- {% if 'PUT' in view.allowed_methods %}
+ {% if 'PUT' in allowed_methods %}
<form action="{{ request.get_full_path }}" method="post" {% if put_form.is_multipart %}enctype="multipart/form-data"{% endif %}>
<fieldset class='module aligned'>
<h2>PUT {{ name }}</h2>
@@ -108,7 +108,7 @@
</form>
{% endif %}
- {% if 'DELETE' in view.allowed_methods %}
+ {% if 'DELETE' in allowed_methods %}
<form action="{{ request.get_full_path }}" method="post">
<fieldset class='module aligned'>
<h2>DELETE {{ name }}</h2>