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
5921e5c8
Commit
5921e5c8
authored
Apr 27, 2011
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up ModelResource issues
parent
5a59f339
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
11 deletions
+12
-11
djangorestframework/emitters.py
+3
-1
djangorestframework/modelresource.py
+5
-3
djangorestframework/resource.py
+1
-4
examples/blogpost/views.py
+3
-3
No files found.
djangorestframework/emitters.py
View file @
5921e5c8
...
@@ -15,8 +15,10 @@ from djangorestframework.breadcrumbs import get_breadcrumbs
...
@@ -15,8 +15,10 @@ from djangorestframework.breadcrumbs import get_breadcrumbs
from
djangorestframework.description
import
get_name
,
get_description
from
djangorestframework.description
import
get_name
,
get_description
from
djangorestframework
import
status
from
djangorestframework
import
status
from
decimal
import
Decimal
from
urllib
import
quote_plus
import
string
import
string
import
re
from
decimal
import
Decimal
# TODO: Rename verbose to something more appropriate
# TODO: Rename verbose to something more appropriate
# TODO: Maybe None could be handled more cleanly. It'd be nice if it was handled by default,
# TODO: Maybe None could be handled more cleanly. It'd be nice if it was handled by default,
...
...
djangorestframework/modelresource.py
View file @
5921e5c8
...
@@ -408,6 +408,9 @@ class ModelResource(Resource):
...
@@ -408,6 +408,9 @@ class ModelResource(Resource):
return
return
class
InstanceModelResource
(
ModelResource
):
http_method_names
=
[
'get'
,
'put'
,
'delete'
,
'head'
,
'options'
,
'trace'
,
'patch'
]
# Bit of a hack, these - needs fixing.
class
RootModelResource
(
ModelResource
):
class
RootModelResource
(
ModelResource
):
"""A Resource which provides default operations for list and create."""
"""A Resource which provides default operations for list and create."""
queryset
=
None
queryset
=
None
...
@@ -416,7 +419,7 @@ class RootModelResource(ModelResource):
...
@@ -416,7 +419,7 @@ class RootModelResource(ModelResource):
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
return
queryset
.
filter
(
**
kwargs
)
return
queryset
.
filter
(
**
kwargs
)
put
=
delete
=
None
http_method_names
=
[
'get'
,
'post'
,
'head'
,
'options'
,
'trace'
,
'patch'
]
class
QueryModelResource
(
ModelResource
):
class
QueryModelResource
(
ModelResource
):
"""Resource with default operations for list.
"""Resource with default operations for list.
...
@@ -428,4 +431,4 @@ class QueryModelResource(ModelResource):
...
@@ -428,4 +431,4 @@ class QueryModelResource(ModelResource):
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
queryset
=
self
.
queryset
if
self
.
queryset
else
self
.
model
.
objects
.
all
()
return
queryset
.
filer
(
**
kwargs
)
return
queryset
.
filer
(
**
kwargs
)
post
=
put
=
delete
=
None
http_method_names
=
[
'get'
,
'head'
,
'options'
,
'trace'
,
'patch'
]
\ No newline at end of file
djangorestframework/resource.py
View file @
5921e5c8
...
@@ -54,7 +54,7 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
...
@@ -54,7 +54,7 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
@property
@property
def
allowed_methods
(
self
):
def
allowed_methods
(
self
):
return
[
method
.
upper
()
for
method
in
self
.
http_method_names
if
getattr
(
self
,
method
,
None
)]
return
[
method
.
upper
()
for
method
in
self
.
http_method_names
if
hasattr
(
self
,
method
)]
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."""
...
@@ -97,9 +97,6 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
...
@@ -97,9 +97,6 @@ class Resource(RequestMixin, ResponseMixin, AuthMixin, View):
# Get the appropriate handler method
# Get the appropriate handler method
if
self
.
method
.
lower
()
in
self
.
http_method_names
:
if
self
.
method
.
lower
()
in
self
.
http_method_names
:
handler
=
getattr
(
self
,
self
.
method
.
lower
(),
self
.
http_method_not_allowed
)
handler
=
getattr
(
self
,
self
.
method
.
lower
(),
self
.
http_method_not_allowed
)
# If a previously defined method has been disabled
if
handler
is
None
:
handler
=
self
.
http_method_not_allowed
else
:
else
:
handler
=
self
.
http_method_not_allowed
handler
=
self
.
http_method_not_allowed
...
...
examples/blogpost/views.py
View file @
5921e5c8
from
djangorestframework.modelresource
import
ModelResource
,
RootModelResource
from
djangorestframework.modelresource
import
Instance
ModelResource
,
RootModelResource
from
blogpost
import
models
from
blogpost
import
models
...
@@ -11,7 +11,7 @@ class BlogPosts(RootModelResource):
...
@@ -11,7 +11,7 @@ class BlogPosts(RootModelResource):
model
=
models
.
BlogPost
model
=
models
.
BlogPost
fields
=
BLOG_POST_FIELDS
fields
=
BLOG_POST_FIELDS
class
BlogPostInstance
(
ModelResource
):
class
BlogPostInstance
(
Instance
ModelResource
):
"""A resource which represents a single blog post."""
"""A resource which represents a single blog post."""
model
=
models
.
BlogPost
model
=
models
.
BlogPost
fields
=
BLOG_POST_FIELDS
fields
=
BLOG_POST_FIELDS
...
@@ -21,7 +21,7 @@ class Comments(RootModelResource):
...
@@ -21,7 +21,7 @@ class Comments(RootModelResource):
model
=
models
.
Comment
model
=
models
.
Comment
fields
=
COMMENT_FIELDS
fields
=
COMMENT_FIELDS
class
CommentInstance
(
ModelResource
):
class
CommentInstance
(
Instance
ModelResource
):
"""A resource which represents a single comment."""
"""A resource which represents a single comment."""
model
=
models
.
Comment
model
=
models
.
Comment
fields
=
COMMENT_FIELDS
fields
=
COMMENT_FIELDS
...
...
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