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
52847a21
Commit
52847a21
authored
Jan 15, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix implementation
parent
8f3931e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
47 deletions
+23
-47
rest_framework/mixins.py
+0
-3
rest_framework/resources.py
+23
-44
No files found.
rest_framework/mixins.py
View file @
52847a21
...
@@ -25,9 +25,6 @@ class CreateModelMixin(object):
...
@@ -25,9 +25,6 @@ class CreateModelMixin(object):
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_201_CREATED
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
Response
(
serializer
.
errors
,
status
=
status
.
HTTP_400_BAD_REQUEST
)
def
pre_save
(
self
,
obj
):
pass
class
ListModelMixin
(
object
):
class
ListModelMixin
(
object
):
"""
"""
...
...
rest_framework/resources.py
View file @
52847a21
##### RESOURCES AND ROUTERS ARE NOT YET IMPLEMENTED - PLACEHOLDER ONLY #####
##### RESOURCES AND ROUTERS ARE NOT YET IMPLEMENTED - PLACEHOLDER ONLY #####
from
functools
import
update_wrapper
from
functools
import
update_wrapper
import
inspect
from
django.utils.decorators
import
classonlymethod
from
django.utils.decorators
import
classonlymethod
from
rest_framework
import
views
,
generics
from
rest_framework
import
views
,
generics
,
mixins
def
wrapped
(
source
,
dest
):
"""
Copy public, non-method attributes from source to dest, and return dest.
"""
for
attr
in
[
attr
for
attr
in
dir
(
source
)
if
not
attr
.
startswith
(
'_'
)
and
not
inspect
.
ismethod
(
attr
)]:
setattr
(
dest
,
attr
,
getattr
(
source
,
attr
))
return
dest
##### RESOURCES AND ROUTERS ARE NOT YET IMPLEMENTED - PLACEHOLDER ONLY #####
##### RESOURCES AND ROUTERS ARE NOT YET IMPLEMENTED - PLACEHOLDER ONLY #####
class
ResourceMixin
(
object
):
class
ResourceMixin
(
object
):
"""
"""
Clone Django's `View.as_view()` behaviour *except* using REST framework's
This is the magic.
'method -> action' binding for resources.
Overrides `.as_view()` so that it takes an `actions` keyword that performs
the binding of HTTP methods to actions on the Resource.
For example, to create a concrete view binding the 'GET' and 'POST' methods
to the 'list' and 'create' actions...
my_resource = MyResource.as_view({'get': 'list', 'post': 'create'})
"""
"""
@classonlymethod
@classonlymethod
def
as_view
(
cls
,
actions
,
**
initkwargs
):
def
as_view
(
cls
,
actions
=
None
,
**
initkwargs
):
"""
"""
Main entry point for a request-response process.
Main entry point for a request-response process.
"""
"""
...
@@ -61,36 +57,19 @@ class ResourceMixin(object):
...
@@ -61,36 +57,19 @@ class ResourceMixin(object):
return
view
return
view
##### RESOURCES AND ROUTERS ARE NOT YET IMPLEMENTED - PLACEHOLDER ONLY #####
class
Resource
(
ResourceMixin
,
views
.
APIView
):
class
Resource
(
ResourceMixin
,
views
.
APIView
):
pass
pass
##### RESOURCES AND ROUTERS ARE NOT YET IMPLEMENTED - PLACEHOLDER ONLY #####
# Note the inheritence of both MultipleObjectAPIView *and* SingleObjectAPIView
# is a bit weird given the diamond inheritence, but it will work for now.
class
ModelResource
(
ResourceMixin
,
views
.
APIView
):
# There's some implementation clean up that can happen later.
# TODO: Actually delegation won't work
class
ModelResource
(
mixins
.
CreateModelMixin
,
root_class
=
generics
.
ListCreateAPIView
mixins
.
RetrieveModelMixin
,
detail_class
=
generics
.
RetrieveUpdateDestroyAPIView
mixins
.
UpdateModelMixin
,
mixins
.
DestroyModelMixin
,
def
root_view
(
self
):
mixins
.
ListModelMixin
,
return
wrapped
(
self
,
self
.
root_class
())
ResourceMixin
,
generics
.
MultipleObjectAPIView
,
def
detail_view
(
self
):
generics
.
SingleObjectAPIView
):
return
wrapped
(
self
,
self
.
detail_class
())
pass
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
root_view
()
.
list
(
request
,
args
,
kwargs
)
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
root_view
()
.
create
(
request
,
args
,
kwargs
)
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
detail_view
()
.
retrieve
(
request
,
args
,
kwargs
)
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
detail_view
()
.
update
(
request
,
args
,
kwargs
)
def
destroy
(
self
,
request
,
*
args
,
**
kwargs
):
return
self
.
detail_view
()
.
destroy
(
request
,
args
,
kwargs
)
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