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
34776da9
Commit
34776da9
authored
May 17, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor mixin refactoring
parent
b6fb377c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
rest_framework/mixins.py
+11
-10
No files found.
rest_framework/mixins.py
View file @
34776da9
...
@@ -43,7 +43,6 @@ def _get_validation_exclusions(obj, pk=None, slug_field=None, lookup_field=None)
...
@@ -43,7 +43,6 @@ def _get_validation_exclusions(obj, pk=None, slug_field=None, lookup_field=None)
class
CreateModelMixin
(
object
):
class
CreateModelMixin
(
object
):
"""
"""
Create a model instance.
Create a model instance.
Should be mixed in with any `GenericAPIView`.
"""
"""
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
serializer
=
self
.
get_serializer
(
data
=
request
.
DATA
,
files
=
request
.
FILES
)
serializer
=
self
.
get_serializer
(
data
=
request
.
DATA
,
files
=
request
.
FILES
)
...
@@ -68,7 +67,6 @@ class CreateModelMixin(object):
...
@@ -68,7 +67,6 @@ class CreateModelMixin(object):
class
ListModelMixin
(
object
):
class
ListModelMixin
(
object
):
"""
"""
List a queryset.
List a queryset.
Should be mixed in with `MultipleObjectAPIView`.
"""
"""
empty_error
=
"Empty list and '
%(class_name)
s.allow_empty' is False."
empty_error
=
"Empty list and '
%(class_name)
s.allow_empty' is False."
...
@@ -101,7 +99,6 @@ class ListModelMixin(object):
...
@@ -101,7 +99,6 @@ class ListModelMixin(object):
class
RetrieveModelMixin
(
object
):
class
RetrieveModelMixin
(
object
):
"""
"""
Retrieve a model instance.
Retrieve a model instance.
Should be mixed in with `SingleObjectAPIView`.
"""
"""
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
self
.
object
=
self
.
get_object
()
...
@@ -112,17 +109,22 @@ class RetrieveModelMixin(object):
...
@@ -112,17 +109,22 @@ class RetrieveModelMixin(object):
class
UpdateModelMixin
(
object
):
class
UpdateModelMixin
(
object
):
"""
"""
Update a model instance.
Update a model instance.
Should be mixed in with `SingleObjectAPIView`.
"""
"""
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
def
get_object_or_none
(
self
):
partial
=
kwargs
.
pop
(
'partial'
,
False
)
self
.
object
=
None
try
:
try
:
self
.
object
=
self
.
get_object
()
return
self
.
get_object
()
except
Http404
:
except
Http404
:
# If this is a PUT-as-create operation, we need to ensure that
# If this is a PUT-as-create operation, we need to ensure that
# we have relevant permissions, as if this was a POST request.
# we have relevant permissions, as if this was a POST request.
self
.
check_permissions
(
clone_request
(
request
,
'POST'
))
# This will either raise a PermissionDenied exception,
# or simply return None
self
.
check_permissions
(
clone_request
(
self
.
request
,
'POST'
))
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
partial
=
kwargs
.
pop
(
'partial'
,
False
)
self
.
object
=
self
.
get_object_or_none
()
if
self
.
object
is
None
:
created
=
True
created
=
True
save_kwargs
=
{
'force_insert'
:
True
}
save_kwargs
=
{
'force_insert'
:
True
}
success_status_code
=
status
.
HTTP_201_CREATED
success_status_code
=
status
.
HTTP_201_CREATED
...
@@ -175,7 +177,6 @@ class UpdateModelMixin(object):
...
@@ -175,7 +177,6 @@ class UpdateModelMixin(object):
class
DestroyModelMixin
(
object
):
class
DestroyModelMixin
(
object
):
"""
"""
Destroy a model instance.
Destroy a model instance.
Should be mixed in with `SingleObjectAPIView`.
"""
"""
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
obj
=
self
.
get_object
()
obj
=
self
.
get_object
()
...
...
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