clearattempts.py 570 B

12345678910111213
  1. from datetime import timedelta
  2. from django.core.management.base import BaseCommand
  3. from django.utils import timezone
  4. from misago.models import SignInAttempt
  5. class Command(BaseCommand):
  6. """
  7. This command is intended to work as CRON job fired every few days to remove failed sign-in attempts
  8. """
  9. help = 'Clears sign-in attempts log'
  10. def handle(self, *args, **options):
  11. SignInAttempt.objects.filter(date__lte=timezone.now() - timedelta(hours=24)).delete()
  12. self.stdout.write('Failed Sign-In attempts older than 24h have been removed.\n')