()
Remove users that have not been activated
Remove users that have not been activated
Remove users that have not been activated
def remove_inactive_users():
    """Remove users that have not been activated"""
    User = get_user_model()

    # time for which to keep unactivated and deleted users
    valid_days = settings.ACTIVATION_VALID_DAYS
    remove_before = datetime.utcnow() - timedelta(days=valid_days)
    logger.warning("Removing unactivated users before %s", remove_before)

    users = User.objects.filter(is_active=False, date_joined__lt=remove_before)

    for user in users:
        clients = models.Client.objects.filter(user=user)
        logger.warning('Deleting %d clients of user "%s"', len(clients), user.username)
        clients.delete()
        logger.warning('Deleting user "%s"', user.username)
        user.delete()
def remove_inactive_users ( ) : User = get_user_model ( ) # time for which to keep unactivated and deleted users valid_days = settings . ACTIVATION_VALID_DAYS remove_before = datetime . utcnow ( ) - timedelta ( days = valid_days ) logger . warning ( "Removing unactivated users before %s" , remove_before ) users = User . objects . filter ( is_active = False , date_joined__lt = remove_before ) for user in users : clients = models . Client . objects . filter ( user = user ) logger . warning ( 'Deleting %d clients of user "%s"' , len ( clients ) , user . username ) clients . delete ( ) logger . warning ( 'Deleting user "%s"' , user . username ) user . delete ( )