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
84a4fd3e
Commit
84a4fd3e
authored
Apr 25, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tidy up
parent
4692374e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
31 deletions
+18
-31
djangorestframework/modelresource.py
+13
-13
djangorestframework/resource.py
+5
-18
No files found.
djangorestframework/modelresource.py
View file @
84a4fd3e
...
...
@@ -341,6 +341,19 @@ class ModelResource(Resource):
return
_any
(
data
,
self
.
fields
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
if
args
:
# If we have any none kwargs then assume the last represents the primrary key
instance
=
self
.
model
.
objects
.
get
(
pk
=
args
[
-
1
],
**
kwargs
)
else
:
# Otherwise assume the kwargs uniquely identify the model
instance
=
self
.
model
.
objects
.
get
(
**
kwargs
)
except
self
.
model
.
DoesNotExist
:
raise
ErrorResponse
(
status
.
HTTP_404_NOT_FOUND
)
return
instance
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO: test creation on a non-existing resource url
...
...
@@ -361,19 +374,6 @@ class ModelResource(Resource):
headers
[
'Location'
]
=
instance
.
get_absolute_url
()
return
Response
(
status
.
HTTP_201_CREATED
,
instance
,
headers
)
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
if
args
:
# If we have any none kwargs then assume the last represents the primrary key
instance
=
self
.
model
.
objects
.
get
(
pk
=
args
[
-
1
],
**
kwargs
)
else
:
# Otherwise assume the kwargs uniquely identify the model
instance
=
self
.
model
.
objects
.
get
(
**
kwargs
)
except
self
.
model
.
DoesNotExist
:
raise
ErrorResponse
(
status
.
HTTP_404_NOT_FOUND
)
return
instance
def
put
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO: update on the url of a non-existing resource url doesn't work correctly at the moment - will end up with a new url
try
:
...
...
djangorestframework/resource.py
View file @
84a4fd3e
...
...
@@ -16,8 +16,8 @@ __all__ = ['Resource']
class
Resource
(
RequestMixin
,
ResponseMixin
,
AuthMixin
,
View
):
"""Handles incoming requests and maps them to REST operations
,
performing authentication, input deserialization, input validation, output serializ
ation."""
"""Handles incoming requests and maps them to REST operations
.
Performs request deserialization, response serialization, authentication and input valid
ation."""
http_method_names
=
[
'get'
,
'post'
,
'put'
,
'delete'
,
'head'
,
'options'
,
'trace'
,
'patch'
]
...
...
@@ -73,21 +73,10 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
return
data
# Session based authentication is explicitly CSRF validated, all other authentication is CSRF exempt.
# Note: session based authentication is explicitly CSRF validated,
# all other authentication is CSRF exempt.
@csrf_exempt
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
"""This method is the core of Resource, through which all requests are passed.
Broadly this consists of the following procedure:
0. ensure the operation is permitted
1. deserialize request content into request data, using standard HTTP content types (PUT/POST only)
2. cleanup and validate request data (PUT/POST only)
3. call the core method to get the response data
4. cleanup the response data
5. serialize response data into response content, using standard HTTP content negotiation
"""
try
:
self
.
request
=
request
self
.
args
=
args
self
.
kwargs
=
kwargs
...
...
@@ -134,7 +123,5 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
response
.
headers
[
'Vary'
]
=
'Authenticate, Accept'
return
self
.
emit
(
response
)
except
:
import
traceback
traceback
.
print_exc
()
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