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
c73d0e1e
Commit
c73d0e1e
authored
Apr 09, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor cleaning up on View
parent
027792c9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
12 deletions
+16
-12
rest_framework/compat.py
+12
-8
rest_framework/views.py
+4
-4
No files found.
rest_framework/compat.py
View file @
c73d0e1e
...
...
@@ -87,9 +87,7 @@ else:
raise
ImportError
(
"User model is not to be found."
)
# First implementation of Django class-based views did not include head method
# in base View class - https://code.djangoproject.com/ticket/15668
if
django
.
VERSION
>=
(
1
,
4
):
if
django
.
VERSION
>=
(
1
,
5
):
from
django.views.generic
import
View
else
:
from
django.views.generic
import
View
as
_View
...
...
@@ -97,6 +95,8 @@ else:
from
django.utils.functional
import
update_wrapper
class
View
(
_View
):
# 1.3 does not include head method in base View class
# See: https://code.djangoproject.com/ticket/15668
@classonlymethod
def
as_view
(
cls
,
**
initkwargs
):
"""
...
...
@@ -126,11 +126,15 @@ else:
update_wrapper
(
view
,
cls
.
dispatch
,
assigned
=
())
return
view
# Taken from @markotibold's attempt at supporting PATCH.
# https://github.com/markotibold/django-rest-framework/tree/patch
http_method_names
=
set
(
View
.
http_method_names
)
http_method_names
.
add
(
'patch'
)
View
.
http_method_names
=
list
(
http_method_names
)
# PATCH method is not implemented by Django
# _allowed_methods only present from 1.5 onwards
def
_allowed_methods
(
self
):
return
[
m
.
upper
()
for
m
in
self
.
http_method_names
if
hasattr
(
self
,
m
)]
# PATCH method is not implemented by Django
if
'patch'
not
in
View
.
http_method_names
:
View
.
http_method_names
=
View
.
http_method_names
+
[
'patch'
]
# PUT, DELETE do not require CSRF until 1.4. They should. Make it better.
if
django
.
VERSION
>=
(
1
,
4
):
...
...
rest_framework/views.py
View file @
c73d0e1e
...
...
@@ -38,10 +38,9 @@ class APIView(View):
@property
def
allowed_methods
(
self
):
"""
Return the list of allowed HTTP methods, uppercased
.
Wrap Django's private `_allowed_methods` interface in a public property
.
"""
return
[
method
.
upper
()
for
method
in
self
.
http_method_names
if
hasattr
(
self
,
method
)]
return
self
.
_allowed_methods
()
@property
def
default_response_headers
(
self
):
...
...
@@ -69,7 +68,8 @@ class APIView(View):
def
http_method_not_allowed
(
self
,
request
,
*
args
,
**
kwargs
):
"""
Called if `request.method` does not correspond to a handler method.
If `request.method` does not correspond to a handler method,
determine what kind of exception to raise.
"""
raise
exceptions
.
MethodNotAllowed
(
request
.
method
)
...
...
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