mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 08:14:16 +03:00
fixed examples, corrected small bugs in the process
This commit is contained in:
parent
b33579a7a1
commit
821844bb11
|
@ -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,
|
||||
|
|
|
@ -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__)
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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__
|
||||
|
|
Loading…
Reference in New Issue
Block a user