from django.core.management.base import BaseCommand
from dateutil.relativedelta import relativedelta

from legalaid.models import Case
from cla_butler.tasks import DeleteOldData


class FindAndDeleteCasesUsingCreationTime(DeleteOldData):
    def get_eligible_cases(self):
        super(FindAndDeleteCasesUsingCreationTime, self)._setup()
        two_years = self.now - relativedelta(years=2)

        return Case.objects.filter(created__lte=two_years).exclude(log__created__gte=two_years)


class Command(BaseCommand):
    help = (
        "Find or delete cases that are 2 years old or over that were not deleted prior to the task command being fixed"
    )

    def handle(self, *args, **kwargs):
        if args[0] == "find":
            cases = FindAndDeleteCasesUsingCreationTime().get_eligible_cases()
            print(cases)
            print(cases.count())

        if args[0] == "delete":
            FindAndDeleteCasesUsingCreationTime().run()

@@ -276,57 +276,13 @@
     
- super(FindAndDeleteCasesUsingCreationTime,
  self
-)
 ._se
@@ -660,46 +660,15 @@
    i
-f args%5B0%5D == %22find%22:%0A            cases
+nstance
  = F
@@ -707,53 +707,84 @@
 me()
-.get_eligible_cases()%0A            print(
+%0A        if len(args) == 0:%0A            cases = instance.get_eligible_
 cases
+(
 )%0A  
@@ -814,25 +814,24 @@
 ount())%0A
-%0A
         
 if args%5B
@@ -822,16 +822,18 @@
         
+el
 if args%5B
@@ -864,45 +864,16 @@
     
-F
 in
-dAndDeleteCasesUsingCreationTime()
+stance
 .run

Refactor command to find cases by default