Skip to content

Accounts cleanup

hypha.apply.users.management.commands.accounts_cleanup

Command

Bases: BaseCommand

help class-attribute instance-attribute

help = '1. Mark all accounts that has not logged in after 5 month after creation as inactive.'

handle

handle(*args, **options)
Source code in hypha/apply/users/management/commands/accounts_cleanup.py
@transaction.atomic
def handle(self, *args, **options):
    onehundredfifty_days_ago = timezone.now() - timedelta(days=150)
    User = get_user_model()
    users_inactivate = User.objects.filter(
        date_joined__date__lte=onehundredfifty_days_ago,
        is_active=True,
        is_staff=False,
        last_login__isnull=True,
    )

    for user in users_inactivate:
        user.is_active = False
        user.save()