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
da4fa9bd
Commit
da4fa9bd
authored
Sep 05, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor tweaks
parent
c28b7193
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
32 deletions
+35
-32
djangorestframework/mixins.py
+22
-21
djangorestframework/request.py
+3
-0
djangorestframework/views.py
+10
-11
No files found.
djangorestframework/mixins.py
View file @
da4fa9bd
...
@@ -2,27 +2,6 @@ from djangorestframework import status
...
@@ -2,27 +2,6 @@ from djangorestframework import status
from
djangorestframework.response
import
Response
from
djangorestframework.response
import
Response
class
MetadataMixin
(
object
):
"""
Should be mixed in with any `BaseView`.
"""
def
metadata
(
self
,
request
,
*
args
,
**
kwargs
):
content
=
{
'name'
:
self
.
get_name
(),
'description'
:
self
.
get_description
(),
'renders'
:
self
.
_rendered_media_types
,
'parses'
:
self
.
_parsed_media_types
,
}
# TODO: Add 'fields', from serializer info.
# form = self.get_bound_form()
# if form is not None:
# field_name_types = {}
# for name, field in form.fields.iteritems():
# field_name_types[name] = field.__class__.__name__
# content['fields'] = field_name_types
raise
Response
(
content
,
status
=
status
.
HTTP_200_OK
)
class
CreateModelMixin
(
object
):
class
CreateModelMixin
(
object
):
"""
"""
Create a model instance.
Create a model instance.
...
@@ -83,3 +62,25 @@ class DestroyModelMixin(object):
...
@@ -83,3 +62,25 @@ class DestroyModelMixin(object):
self
.
object
=
self
.
get_object
()
self
.
object
=
self
.
get_object
()
self
.
object
.
delete
()
self
.
object
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
class
MetadataMixin
(
object
):
"""
Return a dicitonary of view metadata.
Should be mixed in with any `BaseView`.
"""
def
metadata
(
self
,
request
,
*
args
,
**
kwargs
):
content
=
{
'name'
:
self
.
get_name
(),
'description'
:
self
.
get_description
(),
'renders'
:
self
.
_rendered_media_types
,
'parses'
:
self
.
_parsed_media_types
,
}
# TODO: Add 'fields', from serializer info.
# form = self.get_bound_form()
# if form is not None:
# field_name_types = {}
# for name, field in form.fields.iteritems():
# field_name_types[name] = field.__class__.__name__
# content['fields'] = field_name_types
raise
Response
(
content
,
status
=
status
.
HTTP_200_OK
)
djangorestframework/request.py
View file @
da4fa9bd
...
@@ -234,6 +234,9 @@ class Request(object):
...
@@ -234,6 +234,9 @@ class Request(object):
user
=
authentication
.
authenticate
(
self
)
user
=
authentication
.
authenticate
(
self
)
if
user
:
if
user
:
return
user
return
user
return
self
.
_not_authenticated
()
def
_not_authenticated
(
self
):
return
AnonymousUser
()
return
AnonymousUser
()
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
...
...
djangorestframework/views.py
View file @
da4fa9bd
...
@@ -224,18 +224,19 @@ class APIView(_View):
...
@@ -224,18 +224,19 @@ class APIView(_View):
def
initial
(
self
,
request
,
*
args
,
**
kargs
):
def
initial
(
self
,
request
,
*
args
,
**
kargs
):
"""
"""
This method is a hook for any code that needs to run prior to
This method runs prior to anything else in the view.
anything else.
It should return the initial request object.
Required if you want to do things like set `request.upload_handlers`
before the authentication and dispatch handling is run.
You may need to override this if you want to do things like set
`request.upload_handlers` before the authentication and dispatch
handling is run.
"""
"""
pass
return
Request
(
request
,
parsers
=
self
.
parsers
,
authentication
=
self
.
authentication
)
def
final
(
self
,
request
,
response
,
*
args
,
**
kargs
):
def
final
(
self
,
request
,
response
,
*
args
,
**
kargs
):
"""
"""
This method is a hook for any code that needs to run after everything
This method runs after everything else in the view.
else in the view.
It should return the final response object.
Returns the final response object.
"""
"""
if
isinstance
(
response
,
Response
):
if
isinstance
(
response
,
Response
):
response
.
view
=
self
response
.
view
=
self
...
@@ -269,14 +270,12 @@ class APIView(_View):
...
@@ -269,14 +270,12 @@ class APIView(_View):
# all other authentication is CSRF exempt.
# all other authentication is CSRF exempt.
@csrf_exempt
@csrf_exempt
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
request
=
Request
(
request
,
parsers
=
self
.
parsers
,
authentication
=
self
.
authentication
)
self
.
request
=
request
self
.
args
=
args
self
.
args
=
args
self
.
kwargs
=
kwargs
self
.
kwargs
=
kwargs
self
.
headers
=
self
.
default_response_headers
self
.
headers
=
self
.
default_response_headers
try
:
try
:
self
.
initial
(
request
,
*
args
,
**
kwargs
)
self
.
request
=
self
.
initial
(
request
,
*
args
,
**
kwargs
)
# Check that the request is allowed
# Check that the request is allowed
self
.
check_permissions
(
request
)
self
.
check_permissions
(
request
)
...
...
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