From 821844bb11e5262fb0dfc2fecf2add8fe18d3210 Mon Sep 17 00:00:00 2001 From: Sébastien Piquemal Date: Tue, 14 Feb 2012 10:05:28 +0200 Subject: fixed examples, corrected small bugs in the process --- djangorestframework/renderers.py | 3 ++- djangorestframework/response.py | 10 ++++++++-- djangorestframework/templates/renderer.html | 12 ++++++------ examples/pygments_api/views.py | 4 ++-- examples/views.py | 12 +++++------- 5 files changed, 23 insertions(+), 18 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 @@