<commit_before># -*- coding: utf-8 *-*

# This file is part of Workout Manager.
#
# Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License

import datetime

from django.utils.timezone import now
from django.core.management.base import BaseCommand
from wger.manager.models import UserProfile


class Command(BaseCommand):
    '''
    Helper admin command to clean up demo users, to be called e.g. by cron
    '''

    help = 'Deletes all temporary users older than 1 week'

    def handle(self, *args, **options):

        user_list = UserProfile.objects.filter(is_temporary=True)
        for profile in user_list:
            delta = now() - profile.user.date_joined

            if (delta >= datetime.timedelta(7)):
                #self.stdout.write("Deleting user %s, joined %s days ago\n" % (profile,
                #                                                              delta.days))
                profile.user.delete()<commit_msg>Output the number of deleted temporary users<commit_after># -*- coding: utf-8 *-*

# This file is part of Workout Manager.
#
# Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License

import datetime

from django.utils.timezone import now
from django.core.management.base import BaseCommand
from wger.manager.models import UserProfile


class Command(BaseCommand):
    '''
    Helper admin command to clean up demo users, to be called e.g. by cron
    '''

    help = 'Deletes all temporary users older than 1 week'

    def handle(self, *args, **options):

        profile_list = UserProfile.objects.filter(is_temporary=True)
        counter = 0
        for profile in profile_list:
            delta = now() - profile.user.date_joined

            if (delta >= datetime.timedelta(7)):
                counter += 1
                profile.user.delete()

        self.stdout.write("Deleted {0} temporary users".format(counter))
{'fraction_non_alphanumeric': 0.07357973990417523, 'fraction_numerical': 0.0037645448323066393, 'mean_word_length': 2.923489932885906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672640', 'n_tokens_mistral': 759, 'n_tokens_neox': 729, 'n_words': 340}