mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 17:09:59 +03:00
Add more flexible rate attribute.
`rate` attribute allow custom seconds, example: `rate = "1/300"` — 1 request per 5 minutes.
This commit is contained in:
parent
a142467586
commit
8a28da1047
|
@ -103,7 +103,10 @@ class SimpleRateThrottle(BaseThrottle):
|
|||
return (None, None)
|
||||
num, period = rate.split('/')
|
||||
num_requests = int(num)
|
||||
duration = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[period[0]]
|
||||
if not period.isdigit():
|
||||
duration = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}[period[0]]
|
||||
else:
|
||||
duration = int(period)
|
||||
return (num_requests, duration)
|
||||
|
||||
def allow_request(self, request, view):
|
||||
|
|
Loading…
Reference in New Issue
Block a user