diff --git a/djangorestframework/renderers.py b/djangorestframework/renderers.py index 08022c7c9..2cc9cc88f 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 c5fdccbcd..6c42c898d 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 8b5c77c7b..808d96641 100644 --- a/djangorestframework/templates/renderer.html +++ b/djangorestframework/templates/renderer.html @@ -29,7 +29,7 @@
- {% if 'OPTIONS' in view.allowed_methods %} + {% if 'OPTIONS' in allowed_methods %}
{% csrf_token %} @@ -42,11 +42,11 @@

{{ description }}

{{ response.status_code }} {{ response.status_text }}{% autoescape off %}
-{% for key, val in response.headers.items %}{{ key }}: {{ val|urlize_quoted_links }}
+{% for key, val in response.items %}{{ key }}: {{ val|urlize_quoted_links }}
 {% endfor %}
 {{ content|urlize_quoted_links }}
{% endautoescape %}
- {% if 'GET' in view.allowed_methods %} + {% if 'GET' in allowed_methods %}

GET {{ name }}

@@ -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 %}

POST {{ name }}

@@ -86,7 +86,7 @@ {% endif %} - {% if 'PUT' in view.allowed_methods %} + {% if 'PUT' in allowed_methods %}

PUT {{ name }}

@@ -108,7 +108,7 @@ {% endif %} - {% if 'DELETE' in view.allowed_methods %} + {% if 'DELETE' in allowed_methods %}

DELETE {{ name }}

diff --git a/examples/pygments_api/views.py b/examples/pygments_api/views.py index d59a52c00..852b67309 100644 --- a/examples/pygments_api/views.py +++ b/examples/pygments_api/views.py @@ -82,7 +82,7 @@ class PygmentsRoot(View): remove_oldest_files(HIGHLIGHTED_CODE_DIR, MAX_FILES) self.headers['Location'] = reverse('pygments-instance', args=[unique_id]) - return Response(status.HTTP_201_CREATED) + return Response(status=status.HTTP_201_CREATED) class PygmentsInstance(View): @@ -90,7 +90,7 @@ class PygmentsInstance(View): Simply return the stored highlighted HTML file with the correct mime type. This Resource only renders HTML and uses a standard HTML renderer rather than the renderers.DocumentingHTMLRenderer class. """ - renderers = (HTMLRenderer,) + renderer_classes = (HTMLRenderer,) def get(self, request, unique_id): """ diff --git a/examples/views.py b/examples/views.py index e7ef2ec94..e0e4c3c40 100644 --- a/examples/views.py +++ b/examples/views.py @@ -25,10 +25,8 @@ class ProxyView(View): def post(self, request, *args, **kwargs): return Response(self.response.content) - def __getattribute__(self, name): - if name == '__name__': - return self.view_class.__name__ - elif name == '__doc__': - return self.view_class.__doc__ - else: - return super(ProxyView, self).__getattribute__(name) + def get_name(self): + return self.view_class.__name__ + + def get_description(self, html): + return self.view_class.__doc__