Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional reset callable that indicates whether the current counter should be reset to zero. #98

Closed
wants to merge 2 commits into from

Conversation

MarkDoggen
Copy link

A custom reset callable can be passed into the decorator. When set, this reset callable will be called for every request made. The callable can return True/False. If True, the current counter will be reset to zero.

I personally use it to integrate with django-recaptcha like this:

def should_reset(request):
    if request.POST:
        form = ReCaptchaForm(request.POST)
        if form.is_valid():
            return True
    return False

With my view looking like this

@ratelimit(key='ip', rate='10/h', reset=should_reset)
def limited_view(request, **kwargs):
    was_limited = getattr(request, 'limited', False)
    if was_limited:
        return recaptcha_view(request)

@jsocol
Copy link
Owner

jsocol commented Jan 7, 2016

Pinged folks on #36, I'm curious if this helps address those needs.

@jsocol jsocol modified the milestone: 1.2 Jul 30, 2017
@hingston
Copy link

@MarkDoggen @jsocol I'd be really interested in this feature. Is there any chance it would be merged soon?

@ghost
Copy link

ghost commented Dec 30, 2018

I'd be really interested in this feature

@jsocol jsocol modified the milestones: 1.2, 3.0 Feb 20, 2019
@jsocol jsocol closed this Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants