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
4e4584a0
Commit
4e4584a0
authored
Aug 24, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove RequestMixinx / ReponseMixin
parent
372e9450
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
77 deletions
+39
-77
djangorestframework/mixins.py
+0
-73
djangorestframework/tests/renderers.py
+1
-2
djangorestframework/views.py
+38
-2
No files found.
djangorestframework/mixins.py
View file @
4e4584a0
...
...
@@ -11,13 +11,10 @@ from djangorestframework import status
from
djangorestframework.renderers
import
BaseRenderer
from
djangorestframework.resources
import
Resource
,
FormResource
,
ModelResource
from
djangorestframework.response
import
Response
,
ImmediateResponse
from
djangorestframework.request
import
Request
__all__
=
(
# Base behavior mixins
'RequestMixin'
,
'ResponseMixin'
,
'PermissionsMixin'
,
'ResourceMixin'
,
# Model behavior mixins
...
...
@@ -30,76 +27,6 @@ __all__ = (
)
########## Request Mixin ##########
class
RequestMixin
(
object
):
"""
`Mixin` class enabling the use of :class:`request.Request` in your views.
"""
request_class
=
Request
"""
The class to use as a wrapper for the original request object.
"""
def
create_request
(
self
,
request
):
"""
Creates and returns an instance of :class:`request.Request`.
This new instance wraps the `request` passed as a parameter, and use
the parsers set on the view.
"""
return
self
.
request_class
(
request
,
parsers
=
self
.
parsers
,
authentication
=
self
.
authentication
)
@property
def
_parsed_media_types
(
self
):
"""
Return a list of all the media types that this view can parse.
"""
return
[
parser
.
media_type
for
parser
in
self
.
parsers
]
@property
def
_default_parser
(
self
):
"""
Return the view's default parser class.
"""
return
self
.
parsers
[
0
]
########## ResponseMixin ##########
class
ResponseMixin
(
object
):
"""
`Mixin` class enabling the use of :class:`response.Response` in your views.
"""
renderers
=
()
"""
The set of response renderers that the view can handle.
Should be a tuple/list of classes as described in the :mod:`renderers` module.
"""
@property
def
_rendered_media_types
(
self
):
"""
Return an list of all the media types that this response can render.
"""
return
[
renderer
.
media_type
for
renderer
in
self
.
renderers
]
@property
def
_rendered_formats
(
self
):
"""
Return a list of all the formats that this response can render.
"""
return
[
renderer
.
format
for
renderer
in
self
.
renderers
]
@property
def
_default_renderer
(
self
):
"""
Return the response's default renderer class.
"""
return
self
.
renderers
[
0
]
########## Permissions Mixin ##########
class
PermissionsMixin
(
object
):
...
...
djangorestframework/tests/renderers.py
View file @
4e4584a0
...
...
@@ -6,7 +6,6 @@ from django.test import TestCase
from
djangorestframework
import
status
from
djangorestframework.compat
import
View
as
DjangoView
from
djangorestframework.response
import
Response
from
djangorestframework.mixins
import
ResponseMixin
from
djangorestframework.views
import
View
from
djangorestframework.renderers
import
BaseRenderer
,
JSONRenderer
,
YAMLRenderer
,
\
XMLRenderer
,
JSONPRenderer
,
DocumentingHTMLRenderer
...
...
@@ -40,7 +39,7 @@ class RendererB(BaseRenderer):
return
RENDERER_B_SERIALIZER
(
obj
)
class
MockView
(
ResponseMixin
,
Django
View
):
class
MockView
(
View
):
renderers
=
(
RendererA
,
RendererB
)
def
get
(
self
,
request
,
**
kwargs
):
...
...
djangorestframework/views.py
View file @
4e4584a0
...
...
@@ -12,6 +12,7 @@ from django.views.decorators.csrf import csrf_exempt
from
djangorestframework.compat
import
View
as
DjangoView
,
apply_markdown
from
djangorestframework.response
import
Response
,
ImmediateResponse
from
djangorestframework.request
import
Request
from
djangorestframework.mixins
import
*
from
djangorestframework
import
resources
,
renderers
,
parsers
,
authentication
,
permissions
,
status
...
...
@@ -67,7 +68,7 @@ _resource_classes = (
)
class
View
(
ResourceMixin
,
RequestMixin
,
ResponseMixin
,
PermissionsMixin
,
DjangoView
):
class
View
(
ResourceMixin
,
PermissionsMixin
,
DjangoView
):
"""
Handles incoming requests and maps them to REST operations.
Performs request deserialization, response serialization, authentication and input validation.
...
...
@@ -187,6 +188,41 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, PermissionsMixin, DjangoV
}
raise
ImmediateResponse
(
content
,
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
@property
def
_parsed_media_types
(
self
):
"""
Return a list of all the media types that this view can parse.
"""
return
[
parser
.
media_type
for
parser
in
self
.
parsers
]
@property
def
_default_parser
(
self
):
"""
Return the view's default parser class.
"""
return
self
.
parsers
[
0
]
@property
def
_rendered_media_types
(
self
):
"""
Return an list of all the media types that this response can render.
"""
return
[
renderer
.
media_type
for
renderer
in
self
.
renderers
]
@property
def
_rendered_formats
(
self
):
"""
Return a list of all the formats that this response can render.
"""
return
[
renderer
.
format
for
renderer
in
self
.
renderers
]
@property
def
_default_renderer
(
self
):
"""
Return the response's default renderer class.
"""
return
self
.
renderers
[
0
]
def
initial
(
self
,
request
,
*
args
,
**
kargs
):
"""
This method is a hook for any code that needs to run prior to
...
...
@@ -213,7 +249,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, PermissionsMixin, DjangoV
# all other authentication is CSRF exempt.
@csrf_exempt
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
request
=
self
.
create_request
(
request
)
request
=
Request
(
request
,
parsers
=
self
.
parsers
,
authentication
=
self
.
authentication
)
self
.
request
=
request
self
.
args
=
args
...
...
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