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
52298480
Commit
52298480
authored
Jun 14, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up
parent
df957c86
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
rest_framework/throttling.py
+9
-7
No files found.
rest_framework/throttling.py
View file @
52298480
...
...
@@ -188,16 +188,24 @@ class ScopedRateThrottle(SimpleRateThrottle):
scope_attr
=
'throttle_scope'
def
__init__
(
self
):
# Override the usual SimpleRateThrottle, because we can't determine
# the rate until called by the view.
pass
def
allow_request
(
self
,
request
,
view
):
# We can only determine the scope once we're called by the view.
self
.
scope
=
getattr
(
view
,
self
.
scope_attr
,
None
)
# If a view does not have a `throttle_scope` always allow the request
if
not
self
.
scope
:
return
True
# Determine the allowed request rate as we normally would during
# the `__init__` call.
self
.
rate
=
self
.
get_rate
()
self
.
num_requests
,
self
.
duration
=
self
.
parse_rate
(
self
.
rate
)
# We can now proceed as normal.
return
super
(
ScopedRateThrottle
,
self
)
.
allow_request
(
request
,
view
)
def
get_cache_key
(
self
,
request
,
view
):
...
...
@@ -207,18 +215,12 @@ class ScopedRateThrottle(SimpleRateThrottle):
Otherwise generate the unique cache key by concatenating the user id
with the '.throttle_scope` property of the view.
"""
scope
=
getattr
(
view
,
self
.
scope_attr
,
None
)
if
not
scope
:
# Only throttle views if `.throttle_scope` is set on the view.
return
None
if
request
.
user
.
is_authenticated
():
ident
=
request
.
user
.
id
else
:
ident
=
request
.
META
.
get
(
'REMOTE_ADDR'
,
None
)
return
self
.
cache_format
%
{
'scope'
:
scope
,
'scope'
:
s
elf
.
s
cope
,
'ident'
:
ident
}
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