Skip to content

Commit

Permalink
closes #41: Add RATELIMIT_SUPPRESS_WARNINGS setting
Browse files Browse the repository at this point in the history
* Default is False
  • Loading branch information
ciarancourtney committed Nov 19, 2018
1 parent 1f8f485 commit dbb2f14
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ratelimitbackend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from datetime import datetime, timedelta

from django.conf import settings
from django.contrib.auth.backends import ModelBackend
from django.core.cache import cache

Expand All @@ -20,6 +21,8 @@ class RateLimitMixin(object):
requests = 30
username_key = 'username'
no_username = False
suppress_warnings = hasattr(settings, 'RATELIMIT_SUPPRESS_WARNINGS') \
and settings.RATELIMIT_SUPPRESS_WARNINGS

def authenticate(self, request=None, **kwargs):
username = None
Expand All @@ -38,7 +41,7 @@ def authenticate(self, request=None, **kwargs):
)
)
raise RateLimitException('Rate-limit reached', counts)
else:
elif not self.suppress_warnings:
warnings.warn(u"No request passed to the backend, unable to "
u"rate-limit. Username was '%s'" % username,
stacklevel=2)
Expand Down

0 comments on commit dbb2f14

Please sign in to comment.