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
36686cad
Commit
36686cad
authored
Jul 12, 2012
by
Max Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add View.head() method at runtime (should fix AttributeError: object has no attribute 'get')
parent
e53c819c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
2 deletions
+33
-2
djangorestframework/compat.py
+33
-2
No files found.
djangorestframework/compat.py
View file @
36686cad
...
@@ -68,12 +68,41 @@ except ImportError:
...
@@ -68,12 +68,41 @@ except ImportError:
# django.views.generic.View (Django >= 1.3)
# django.views.generic.View (Django >= 1.3)
try
:
try
:
from
django.views.generic
import
View
from
django.views.generic
import
View
from
django.utils.decorators
import
classonlymethod
from
django.utils.functional
import
update_wrapper
if
not
hasattr
(
View
,
'head'
):
if
not
hasattr
(
View
,
'head'
):
# First implementation of Django class-based views did not include head method
# First implementation of Django class-based views did not include head method
# in base View class - https://code.djangoproject.com/ticket/15668
# in base View class - https://code.djangoproject.com/ticket/15668
class
ViewPlusHead
(
View
):
class
ViewPlusHead
(
View
):
def
head
(
self
,
request
,
*
args
,
**
kwargs
):
@classonlymethod
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
def
as_view
(
cls
,
**
initkwargs
):
"""
Main entry point for a request-response process.
"""
# sanitize keyword arguments
for
key
in
initkwargs
:
if
key
in
cls
.
http_method_names
:
raise
TypeError
(
u"You tried to pass in the
%
s method name as a "
u"keyword argument to
%
s(). Don't do that."
%
(
key
,
cls
.
__name__
))
if
not
hasattr
(
cls
,
key
):
raise
TypeError
(
u"
%
s() received an invalid keyword
%
r"
%
(
cls
.
__name__
,
key
))
def
view
(
request
,
*
args
,
**
kwargs
):
self
=
cls
(
**
initkwargs
)
if
hasattr
(
self
,
'get'
)
and
not
hasattr
(
self
,
'head'
):
self
.
head
=
self
.
get
return
self
.
dispatch
(
request
,
*
args
,
**
kwargs
)
# take name and docstring from class
update_wrapper
(
view
,
cls
,
updated
=
())
# and possible attributes set by decorators
# like csrf_exempt from dispatch
update_wrapper
(
view
,
cls
.
dispatch
,
assigned
=
())
return
view
View
=
ViewPlusHead
View
=
ViewPlusHead
except
ImportError
:
except
ImportError
:
...
@@ -121,6 +150,8 @@ except ImportError:
...
@@ -121,6 +150,8 @@ except ImportError:
def
view
(
request
,
*
args
,
**
kwargs
):
def
view
(
request
,
*
args
,
**
kwargs
):
self
=
cls
(
**
initkwargs
)
self
=
cls
(
**
initkwargs
)
if
hasattr
(
self
,
'get'
)
and
not
hasattr
(
self
,
'head'
):
self
.
head
=
self
.
get
return
self
.
dispatch
(
request
,
*
args
,
**
kwargs
)
return
self
.
dispatch
(
request
,
*
args
,
**
kwargs
)
# take name and docstring from class
# take name and docstring from class
...
...
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