Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
821844bb
Commit
821844bb
authored
Feb 14, 2012
by
Sébastien Piquemal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed examples, corrected small bugs in the process
parent
b33579a7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
18 deletions
+23
-18
djangorestframework/renderers.py
+2
-1
djangorestframework/response.py
+8
-2
djangorestframework/templates/renderer.html
+6
-6
examples/pygments_api/views.py
+2
-2
examples/views.py
+5
-7
No files found.
djangorestframework/renderers.py
View file @
821844bb
...
@@ -13,7 +13,7 @@ from django.utils import simplejson as json
...
@@ -13,7 +13,7 @@ from django.utils import simplejson as json
from
djangorestframework.compat
import
yaml
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.breadcrumbs
import
get_breadcrumbs
from
djangorestframework.utils.mediatypes
import
get_media_type_params
,
add_media_type_param
,
media_type_matches
from
djangorestframework.utils.mediatypes
import
get_media_type_params
,
add_media_type_param
,
media_type_matches
from
djangorestframework
import
VERSION
from
djangorestframework
import
VERSION
...
@@ -349,6 +349,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
...
@@ -349,6 +349,7 @@ class DocumentingTemplateRenderer(BaseRenderer):
'name'
:
name
,
'name'
:
name
,
'version'
:
VERSION
,
'version'
:
VERSION
,
'breadcrumblist'
:
breadcrumb_list
,
'breadcrumblist'
:
breadcrumb_list
,
'allowed_methods'
:
allowed_methods
(
self
.
view
),
'available_formats'
:
self
.
view
.
_rendered_formats
,
'available_formats'
:
self
.
view
.
_rendered_formats
,
'put_form'
:
put_form_instance
,
'put_form'
:
put_form_instance
,
'post_form'
:
post_form_instance
,
'post_form'
:
post_form_instance
,
...
...
djangorestframework/response.py
View file @
821844bb
...
@@ -75,7 +75,7 @@ class Response(SimpleTemplateResponse):
...
@@ -75,7 +75,7 @@ class Response(SimpleTemplateResponse):
Returns reason text corresponding to our HTTP response status code.
Returns reason text corresponding to our HTTP response status code.
Provided for convenience.
Provided for convenience.
"""
"""
return
STATUS_CODE_TEXT
.
get
(
self
.
status
,
''
)
return
STATUS_CODE_TEXT
.
get
(
self
.
status
_code
,
''
)
def
_determine_accept_list
(
self
):
def
_determine_accept_list
(
self
):
"""
"""
...
@@ -166,5 +166,11 @@ class ImmediateResponse(Response, BaseException):
...
@@ -166,5 +166,11 @@ class ImmediateResponse(Response, BaseException):
"""
"""
A subclass of :class:`Response` used to abort the current request handling.
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__
)
djangorestframework/templates/renderer.html
View file @
821844bb
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
<div
id=
"content"
class=
"{% block coltype %}colM{% endblock %}"
>
<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"
>
<form
action=
"{{ request.get_full_path }}"
method=
"post"
>
{% csrf_token %}
{% csrf_token %}
<input
type=
"hidden"
name=
"{{ METHOD_PARAM }}"
value=
"OPTIONS"
/>
<input
type=
"hidden"
name=
"{{ METHOD_PARAM }}"
value=
"OPTIONS"
/>
...
@@ -42,11 +42,11 @@
...
@@ -42,11 +42,11 @@
<p>
{{ description }}
</p>
<p>
{{ description }}
</p>
<div
class=
'module'
>
<div
class=
'module'
>
<pre><b>
{{ response.status_code }} {{ response.status_text }}
</b>
{% autoescape off %}
<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 %}
{% endfor %}
{{ content|urlize_quoted_links }}
</pre>
{% endautoescape %}
</div>
{{ content|urlize_quoted_links }}
</pre>
{% endautoescape %}
</div>
{% if 'GET' in
view.
allowed_methods %}
{% if 'GET' in allowed_methods %}
<form>
<form>
<fieldset
class=
'module aligned'
>
<fieldset
class=
'module aligned'
>
<h2>
GET {{ name }}
</h2>
<h2>
GET {{ name }}
</h2>
...
@@ -65,7 +65,7 @@
...
@@ -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. #}
{# 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 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
%}
>
<form
action=
"{{ request.get_full_path }}"
method=
"post"
{%
if
post_form
.
is_multipart
%}
enctype=
"multipart/form-data"
{%
endif
%}
>
<fieldset
class=
'module aligned'
>
<fieldset
class=
'module aligned'
>
<h2>
POST {{ name }}
</h2>
<h2>
POST {{ name }}
</h2>
...
@@ -86,7 +86,7 @@
...
@@ -86,7 +86,7 @@
</form>
</form>
{% endif %}
{% 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
%}
>
<form
action=
"{{ request.get_full_path }}"
method=
"post"
{%
if
put_form
.
is_multipart
%}
enctype=
"multipart/form-data"
{%
endif
%}
>
<fieldset
class=
'module aligned'
>
<fieldset
class=
'module aligned'
>
<h2>
PUT {{ name }}
</h2>
<h2>
PUT {{ name }}
</h2>
...
@@ -108,7 +108,7 @@
...
@@ -108,7 +108,7 @@
</form>
</form>
{% endif %}
{% endif %}
{% if 'DELETE' in
view.
allowed_methods %}
{% if 'DELETE' in allowed_methods %}
<form
action=
"{{ request.get_full_path }}"
method=
"post"
>
<form
action=
"{{ request.get_full_path }}"
method=
"post"
>
<fieldset
class=
'module aligned'
>
<fieldset
class=
'module aligned'
>
<h2>
DELETE {{ name }}
</h2>
<h2>
DELETE {{ name }}
</h2>
...
...
examples/pygments_api/views.py
View file @
821844bb
...
@@ -82,7 +82,7 @@ class PygmentsRoot(View):
...
@@ -82,7 +82,7 @@ class PygmentsRoot(View):
remove_oldest_files
(
HIGHLIGHTED_CODE_DIR
,
MAX_FILES
)
remove_oldest_files
(
HIGHLIGHTED_CODE_DIR
,
MAX_FILES
)
self
.
headers
[
'Location'
]
=
reverse
(
'pygments-instance'
,
args
=
[
unique_id
])
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
):
class
PygmentsInstance
(
View
):
...
@@ -90,7 +90,7 @@ class PygmentsInstance(View):
...
@@ -90,7 +90,7 @@ class PygmentsInstance(View):
Simply return the stored highlighted HTML file with the correct mime type.
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.
This Resource only renders HTML and uses a standard HTML renderer rather than the renderers.DocumentingHTMLRenderer class.
"""
"""
renderers
=
(
HTMLRenderer
,)
renderer
_classe
s
=
(
HTMLRenderer
,)
def
get
(
self
,
request
,
unique_id
):
def
get
(
self
,
request
,
unique_id
):
"""
"""
...
...
examples/views.py
View file @
821844bb
...
@@ -25,10 +25,8 @@ class ProxyView(View):
...
@@ -25,10 +25,8 @@ class ProxyView(View):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
return
Response
(
self
.
response
.
content
)
return
Response
(
self
.
response
.
content
)
def
__getattribute__
(
self
,
name
):
def
get_name
(
self
):
if
name
==
'__name__'
:
return
self
.
view_class
.
__name__
return
self
.
view_class
.
__name__
elif
name
==
'__doc__'
:
def
get_description
(
self
,
html
):
return
self
.
view_class
.
__doc__
return
self
.
view_class
.
__doc__
else
:
return
super
(
ProxyView
,
self
)
.
__getattribute__
(
name
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment