django-axes/axes/utils.py

21 lines
462 B
Python
Raw Normal View History

from axes.models import AccessAttempt
2011-04-12 21:04:51 +00:00
2013-07-27 17:16:54 +00:00
def reset(ip=None, username=None):
"""Reset records that match ip or username, and
return the count of removed attempts.
"""
count = 0
2013-07-27 17:16:54 +00:00
attempts = AccessAttempt.objects.all()
if ip:
2013-07-27 17:16:54 +00:00
attempts = attempts.filter(ip_address=ip)
if username:
2013-07-27 17:16:54 +00:00
attempts = attempts.filter(username=username)
if attempts:
2013-07-27 17:16:54 +00:00
count = attempts.count()
attempts.delete()
2013-07-27 17:16:54 +00:00
return count