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
42cdd005
Commit
42cdd005
authored
Dec 09, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge meurig's absolute_url fix.
parents
325ee1e3
e7047053
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
21 deletions
+24
-21
AUTHORS
+1
-0
djangorestframework/views.py
+23
-21
No files found.
AUTHORS
View file @
42cdd005
...
@@ -18,6 +18,7 @@ Tom Drummond <devioustree>
...
@@ -18,6 +18,7 @@ Tom Drummond <devioustree>
Danilo Bargen <gwrtheyrn>
Danilo Bargen <gwrtheyrn>
Andrew McCloud <amccloud>
Andrew McCloud <amccloud>
Thomas Steinacher <thomasst>
Thomas Steinacher <thomasst>
Meurig Freeman <meurig>
THANKS TO:
THANKS TO:
...
...
djangorestframework/views.py
View file @
42cdd005
...
@@ -5,7 +5,7 @@ be subclassing in your implementation.
...
@@ -5,7 +5,7 @@ be subclassing in your implementation.
By setting or modifying class attributes on your view, you change it's predefined behaviour.
By setting or modifying class attributes on your view, you change it's predefined behaviour.
"""
"""
from
django.core.urlresolvers
import
set_script_prefix
from
django.core.urlresolvers
import
set_script_prefix
,
get_script_prefix
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
...
@@ -42,7 +42,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -42,7 +42,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
List of renderers the resource can serialize the response with, ordered by preference.
List of renderers the resource can serialize the response with, ordered by preference.
"""
"""
renderers
=
renderers
.
DEFAULT_RENDERERS
renderers
=
renderers
.
DEFAULT_RENDERERS
"""
"""
List of parsers the resource can parse the request with.
List of parsers the resource can parse the request with.
"""
"""
...
@@ -53,19 +53,19 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -53,19 +53,19 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
"""
"""
authentication
=
(
authentication
.
UserLoggedInAuthentication
,
authentication
=
(
authentication
.
UserLoggedInAuthentication
,
authentication
.
BasicAuthentication
)
authentication
.
BasicAuthentication
)
"""
"""
List of all permissions that must be checked.
List of all permissions that must be checked.
"""
"""
permissions
=
(
permissions
.
FullAnonAccess
,
)
permissions
=
(
permissions
.
FullAnonAccess
,
)
@classmethod
@classmethod
def
as_view
(
cls
,
**
initkwargs
):
def
as_view
(
cls
,
**
initkwargs
):
"""
"""
Override the default :meth:`as_view` to store an instance of the view
Override the default :meth:`as_view` to store an instance of the view
as an attribute on the callable function. This allows us to discover
as an attribute on the callable function. This allows us to discover
information about the view when we do URL reverse lookups.
information about the view when we do URL reverse lookups.
"""
"""
view
=
super
(
View
,
cls
)
.
as_view
(
**
initkwargs
)
view
=
super
(
View
,
cls
)
.
as_view
(
**
initkwargs
)
view
.
cls_instance
=
cls
(
**
initkwargs
)
view
.
cls_instance
=
cls
(
**
initkwargs
)
...
@@ -82,7 +82,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -82,7 +82,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
def
http_method_not_allowed
(
self
,
request
,
*
args
,
**
kwargs
):
def
http_method_not_allowed
(
self
,
request
,
*
args
,
**
kwargs
):
"""
"""
Return an HTTP 405 error if an operation is called which does not have a handler method.
Return an HTTP 405 error if an operation is called which does not have a handler method.
"""
"""
raise
ErrorResponse
(
status
.
HTTP_405_METHOD_NOT_ALLOWED
,
raise
ErrorResponse
(
status
.
HTTP_405_METHOD_NOT_ALLOWED
,
{
'detail'
:
'Method
\'
%
s
\'
not allowed on this resource.'
%
self
.
method
})
{
'detail'
:
'Method
\'
%
s
\'
not allowed on this resource.'
%
self
.
method
})
...
@@ -99,7 +99,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -99,7 +99,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
def
add_header
(
self
,
field
,
value
):
def
add_header
(
self
,
field
,
value
):
"""
"""
Add *field* and *value* to the :attr:`headers` attribute of the :class:`View` class.
Add *field* and *value* to the :attr:`headers` attribute of the :class:`View` class.
"""
"""
self
.
headers
[
field
]
=
value
self
.
headers
[
field
]
=
value
...
@@ -114,12 +114,13 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -114,12 +114,13 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
self
.
headers
=
{}
self
.
headers
=
{}
# Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here.
# Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here.
orig_prefix
=
get_script_prefix
()
prefix
=
'
%
s://
%
s'
%
(
request
.
is_secure
()
and
'https'
or
'http'
,
request
.
get_host
())
prefix
=
'
%
s://
%
s'
%
(
request
.
is_secure
()
and
'https'
or
'http'
,
request
.
get_host
())
set_script_prefix
(
prefix
)
set_script_prefix
(
prefix
+
orig_prefix
)
try
:
try
:
self
.
initial
(
request
,
*
args
,
**
kwargs
)
self
.
initial
(
request
,
*
args
,
**
kwargs
)
# Authenticate and check request has the relevant permissions
# Authenticate and check request has the relevant permissions
self
.
_check_permissions
()
self
.
_check_permissions
()
...
@@ -148,27 +149,28 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
...
@@ -148,27 +149,28 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView):
else
:
else
:
# Pre-serialize filtering (eg filter complex objects into natively serializable types)
# Pre-serialize filtering (eg filter complex objects into natively serializable types)
response
.
cleaned_content
=
self
.
filter_response
(
response
.
raw_content
)
response
.
cleaned_content
=
self
.
filter_response
(
response
.
raw_content
)
except
ErrorResponse
,
exc
:
except
ErrorResponse
,
exc
:
response
=
exc
.
response
response
=
exc
.
response
# Always add these headers.
# Always add these headers.
#
#
# TODO - this isn't actually the correct way to set the vary header,
# TODO - this isn't actually the correct way to set the vary header,
# also it's currently sub-obtimal for HTTP caching - need to sort that out.
# also it's currently sub-obtimal for HTTP caching - need to sort that out.
response
.
headers
[
'Allow'
]
=
', '
.
join
(
self
.
allowed_methods
)
response
.
headers
[
'Allow'
]
=
', '
.
join
(
self
.
allowed_methods
)
response
.
headers
[
'Vary'
]
=
'Authenticate, Accept'
response
.
headers
[
'Vary'
]
=
'Authenticate, Accept'
# merge with headers possibly set at some point in the view
# merge with headers possibly set at some point in the view
response
.
headers
.
update
(
self
.
headers
)
response
.
headers
.
update
(
self
.
headers
)
return
self
.
render
(
response
)
set_script_prefix
(
orig_prefix
)
return
self
.
render
(
response
)
def
options
(
self
,
request
,
*
args
,
**
kwargs
):
def
options
(
self
,
request
,
*
args
,
**
kwargs
):
response_obj
=
{
response_obj
=
{
'name'
:
get_name
(
self
),
'name'
:
get_name
(
self
),
'description'
:
get_description
(
self
),
'description'
:
get_description
(
self
),
'renders'
:
self
.
_rendered_media_types
,
'renders'
:
self
.
_rendered_media_types
,
'parses'
:
self
.
_parsed_media_types
,
'parses'
:
self
.
_parsed_media_types
,
}
}
...
@@ -196,11 +198,11 @@ class InstanceModelView(InstanceMixin, ReadModelMixin, UpdateModelMixin, DeleteM
...
@@ -196,11 +198,11 @@ class InstanceModelView(InstanceMixin, ReadModelMixin, UpdateModelMixin, DeleteM
class
ListModelView
(
ListModelMixin
,
ModelView
):
class
ListModelView
(
ListModelMixin
,
ModelView
):
"""
"""
A view which provides default operations for list, against a model in the database.
A view which provides default operations for list, against a model in the database.
"""
"""
_suffix
=
'List'
_suffix
=
'List'
class
ListOrCreateModelView
(
ListModelMixin
,
CreateModelMixin
,
ModelView
):
class
ListOrCreateModelView
(
ListModelMixin
,
CreateModelMixin
,
ModelView
):
"""
"""
A view which provides default operations for list and create, against a model in the database.
A view which provides default operations for list and create, against a model in the database.
"""
"""
_suffix
=
'List'
_suffix
=
'List'
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