chores.py 726 B

1234567891011121314151617
  1. from django.conf import settings
  2. from django.core.management import BaseCommand
  3. from django.utils import timezone
  4. from desecapi.models import Captcha, User
  5. class Command(BaseCommand):
  6. def handle(self, *args, **kwargs):
  7. # delete expired captchas
  8. Captcha.objects.filter(created__lt=timezone.now() - settings.CAPTCHA_VALIDITY_PERIOD).delete()
  9. # delete inactive users whose activation link expired and who never logged in
  10. # (this will not delete users who have used their account and were later disabled)
  11. User.objects.filter(is_active=False, last_login__exact=None,
  12. created__lt=timezone.now() - settings.VALIDITY_PERIOD_VERIFICATION_SIGNATURE).delete()