forked from jsocol/django-ratelimit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added error message and clear function
- Loading branch information
kpd
committed
Dec 29, 2012
1 parent
a148254
commit 1d34d35
Showing
3 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,11 @@ def _split_rate(rate): | |
|
||
|
||
_backend = CacheBackend() | ||
def clear(request, ip=True, field=None): | ||
"reset counts for these parameters" | ||
_backend.clear(request, ip, field) | ||
|
||
|
||
def ratelimit(ip=True, block=False, method=['POST'], field=None, rate='5/m'): | ||
def ratelimit(ip=True, block=False, method=['POST'], field=None, rate='5/m', error_message=None): | ||
def decorator(fn): | ||
count, period = _split_rate(rate) | ||
|
||
|
@@ -47,7 +49,7 @@ def _wrapped(request, *args, **kw): | |
_backend.count(request, ip, field, period) | ||
if _backend.limit(request, ip, field, count): | ||
if block: | ||
return HttpResponseForbidden() | ||
return HttpResponseForbidden() if error_message is None else HttpResponseForbidden(error_message) | ||
This comment has been minimized.
Sorry, something went wrong.
jsocol
|
||
request.limited = True | ||
return fn(request, *args, **kw) | ||
return _wrapped | ||
|
This example should be
clear(request, field='username')
, right?