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
027c9079
Commit
027c9079
authored
Oct 31, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PUT as create should return 201. Fixes #340.
parent
3a99170a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
7 deletions
+10
-7
docs/topics/release-notes.md
+4
-0
rest_framework/mixins.py
+3
-4
rest_framework/tests/generics.py
+3
-3
No files found.
docs/topics/release-notes.md
View file @
027c9079
...
@@ -4,6 +4,10 @@
...
@@ -4,6 +4,10 @@
>
>
> — Eric S. Raymond, [The Cathedral and the Bazaar][cite].
> — Eric S. Raymond, [The Cathedral and the Bazaar][cite].
## Master
*
If PUT creates an instance return '201 Created', instead of '200 OK'.
## 2.0.0
## 2.0.0
*
**Fix all of the things.**
(Well, almost.)
*
**Fix all of the things.**
(Well, almost.)
...
...
rest_framework/mixins.py
View file @
027c9079
...
@@ -3,9 +3,6 @@ Basic building blocks for generic class based views.
...
@@ -3,9 +3,6 @@ Basic building blocks for generic class based views.
We don't bind behaviour to http method handlers yet,
We don't bind behaviour to http method handlers yet,
which allows mixin classes to be composed in interesting ways.
which allows mixin classes to be composed in interesting ways.
Eg. Use mixins to build a Resource class, and have a Router class
perform the binding of http methods to actions for us.
"""
"""
from
django.http
import
Http404
from
django.http
import
Http404
from
rest_framework
import
status
from
rest_framework
import
status
...
@@ -78,15 +75,17 @@ class UpdateModelMixin(object):
...
@@ -78,15 +75,17 @@ class UpdateModelMixin(object):
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
try
:
try
:
self
.
object
=
self
.
get_object
()
self
.
object
=
self
.
get_object
()
success_status
=
status
.
HTTP_200_OK
except
Http404
:
except
Http404
:
self
.
object
=
None
self
.
object
=
None
success_status
=
status
.
HTTP_201_CREATED
serializer
=
self
.
get_serializer
(
data
=
request
.
DATA
,
instance
=
self
.
object
)
serializer
=
self
.
get_serializer
(
data
=
request
.
DATA
,
instance
=
self
.
object
)
if
serializer
.
is_valid
():
if
serializer
.
is_valid
():
self
.
pre_save
(
serializer
.
object
)
self
.
pre_save
(
serializer
.
object
)
self
.
object
=
serializer
.
save
()
self
.
object
=
serializer
.
save
()
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
,
status
=
success_status
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
...
...
rest_framework/tests/generics.py
View file @
027c9079
...
@@ -236,7 +236,7 @@ class TestInstanceView(TestCase):
...
@@ -236,7 +236,7 @@ class TestInstanceView(TestCase):
request
=
factory
.
put
(
'/1'
,
json
.
dumps
(
content
),
request
=
factory
.
put
(
'/1'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
content_type
=
'application/json'
)
response
=
self
.
view
(
request
,
pk
=
1
)
.
render
()
response
=
self
.
view
(
request
,
pk
=
1
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_20
0_OK
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_20
1_CREATED
)
self
.
assertEquals
(
response
.
data
,
{
'id'
:
1
,
'text'
:
'foobar'
})
self
.
assertEquals
(
response
.
data
,
{
'id'
:
1
,
'text'
:
'foobar'
})
updated
=
self
.
objects
.
get
(
id
=
1
)
updated
=
self
.
objects
.
get
(
id
=
1
)
self
.
assertEquals
(
updated
.
text
,
'foobar'
)
self
.
assertEquals
(
updated
.
text
,
'foobar'
)
...
@@ -251,7 +251,7 @@ class TestInstanceView(TestCase):
...
@@ -251,7 +251,7 @@ class TestInstanceView(TestCase):
request
=
factory
.
put
(
'/5'
,
json
.
dumps
(
content
),
request
=
factory
.
put
(
'/5'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
content_type
=
'application/json'
)
response
=
self
.
view
(
request
,
pk
=
5
)
.
render
()
response
=
self
.
view
(
request
,
pk
=
5
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_20
0_OK
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_20
1_CREATED
)
new_obj
=
self
.
objects
.
get
(
pk
=
5
)
new_obj
=
self
.
objects
.
get
(
pk
=
5
)
self
.
assertEquals
(
new_obj
.
text
,
'foobar'
)
self
.
assertEquals
(
new_obj
.
text
,
'foobar'
)
...
@@ -264,7 +264,7 @@ class TestInstanceView(TestCase):
...
@@ -264,7 +264,7 @@ class TestInstanceView(TestCase):
request
=
factory
.
put
(
'/test_slug'
,
json
.
dumps
(
content
),
request
=
factory
.
put
(
'/test_slug'
,
json
.
dumps
(
content
),
content_type
=
'application/json'
)
content_type
=
'application/json'
)
response
=
self
.
slug_based_view
(
request
,
slug
=
'test_slug'
)
.
render
()
response
=
self
.
slug_based_view
(
request
,
slug
=
'test_slug'
)
.
render
()
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_20
0_OK
)
self
.
assertEquals
(
response
.
status_code
,
status
.
HTTP_20
1_CREATED
)
self
.
assertEquals
(
response
.
data
,
{
'slug'
:
'test_slug'
,
'text'
:
'foobar'
})
self
.
assertEquals
(
response
.
data
,
{
'slug'
:
'test_slug'
,
'text'
:
'foobar'
})
new_obj
=
SlugBasedModel
.
objects
.
get
(
slug
=
'test_slug'
)
new_obj
=
SlugBasedModel
.
objects
.
get
(
slug
=
'test_slug'
)
self
.
assertEquals
(
new_obj
.
text
,
'foobar'
)
self
.
assertEquals
(
new_obj
.
text
,
'foobar'
)
...
...
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