<commit_before>from optparse import make_option
from django.core.management.base import BaseCommand
from datetime import timedelta
from django.utils.timezone import now
from alert.donate.models import Donation


TOO_MANY_DAYS_AGO = now() - timedelta(days=7)


class Command(BaseCommand):
    help = 'Deletes donations that never went through so they are not in ' \
           'the database forever.'
    option_list = BaseCommand.option_list + (
        make_option(
            '--simulate',
            dest='simulate',
            action='store_true',
            default=False,
            help='Run the command in simulate mode so that no items are '
                 'actually deleted.'
        ),
    )

    def handle(self, *args, **options):
        simulate = options['simulate']

        self.stdout.write('#########################\n')
        if simulate:
            self.stdout.write('# SIMULATE MODE IS ON.  #\n')
        else:
            self.stdout.write('# SIMULATE MODE IS OFF. #\n')
        self.stdout.write('#########################\n')

        # The statuses here are rather conservative and will likely need
        # updating as further failed payments trickle in.
        qs = {
            'Dwolla': Donation.objects.filter(
                payment_provider='dwolla',
                date_created__lt=TOO_MANY_DAYS_AGO,
                status__in=[
                    0,  # Awaiting payment
                    1,  # Unknown error
                ],
            ),
            'PayPal': Donation.objects.filter(
                payment_provider='paypal',
                date_created__lt=TOO_MANY_DAYS_AGO,
                status__in=[
                    0,
                    1,
                ]
            ),
            'Stripe': Donation.objects.filter(
                payment_provider='stripe',
                date_created__lt=TOO_MANY_DAYS_AGO,
                status__in=[
                    0,
                ]
            ),<commit_msg>Cancelled paypal donations can be deleted once old.<commit_after>from optparse import make_option
from django.core.management.base import BaseCommand
from datetime import timedelta
from django.utils.timezone import now
from alert.donate.models import Donation


TOO_MANY_DAYS_AGO = now() - timedelta(days=7)


class Command(BaseCommand):
    help = 'Deletes donations that never went through so they are not in ' \
           'the database forever.'
    option_list = BaseCommand.option_list + (
        make_option(
            '--simulate',
            dest='simulate',
            action='store_true',
            default=False,
            help='Run the command in simulate mode so that no items are '
                 'actually deleted.'
        ),
    )

    def handle(self, *args, **options):
        simulate = options['simulate']

        self.stdout.write('#########################\n')
        if simulate:
            self.stdout.write('# SIMULATE MODE IS ON.  #\n')
        else:
            self.stdout.write('# SIMULATE MODE IS OFF. #\n')
        self.stdout.write('#########################\n')

        # The statuses here are rather conservative and will likely need
        # updating as further failed payments trickle in.
        qs = {
            'Dwolla': Donation.objects.filter(
                payment_provider='dwolla',
                date_created__lt=TOO_MANY_DAYS_AGO,
                status__in=[
                    0,  # Awaiting payment
                    1,  # Unknown error
                ],
            ),
            'PayPal': Donation.objects.filter(
                payment_provider='paypal',
                date_created__lt=TOO_MANY_DAYS_AGO,
                status__in=[
                    0,
                    1,
                    3,  # Cancelled
                ]
            ),
            'Stripe': Donation.objects.filter(
                payment_provider='stripe',
                date_created__lt=TOO_MANY_DAYS_AGO,
                status__in=[
                    0,
                ]
            ),
{'fraction_non_alphanumeric': 0.10905044510385757, 'fraction_numerical': 0.003214638971315529, 'mean_word_length': 1.5879718490083174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2368458', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1047, 'n_words': 259}