improve cleanup commands

This commit is contained in:
Your Name 2023-01-08 20:28:18 -05:00
parent 578330686e
commit d4dd40ccac
3 changed files with 10 additions and 11 deletions

View file

@ -4,13 +4,13 @@ from catalog.models import *
class Command(BaseCommand):
help = "Scrape a catalog item from external resource (and save it)"
help = "catalog app utilities"
def add_arguments(self, parser):
parser.add_argument(
"--cleanup",
action="store_true",
help="purge invalid data",
help="purge invalid data (is_deleted=true)",
)
def handle(self, *args, **options):

View file

@ -51,8 +51,8 @@ class Command(BaseCommand):
self.stdout.write("Please wait for previous updates")
# Indexer.update_settings()
# self.stdout.write(self.style.SUCCESS('Index settings updated.'))
qs = (
Item.objects.all()
qs = Item.objects.filter(
is_deleted=False
) # if h == 0 else c.objects.filter(edited_time__gt=timezone.now() - timedelta(hours=h))
pg = Paginator(qs.order_by("id"), BATCH_SIZE)
for p in tqdm(pg.page_range):

View file

@ -4,21 +4,20 @@ from journal.models import *
class Command(BaseCommand):
help = "Scrape a catalog item from external resource (and save it)"
help = "journal app utilities"
def add_arguments(self, parser):
parser.add_argument(
"--cleanup",
action="store_true",
help="purge invalid data",
help="purge invalid data (visibility=99)",
)
def handle(self, *args, **options):
if options["cleanup"]:
self.stdout.write(f"Cleaning up Rating...")
Rating.objects.filter(grade=0).delete()
for cls in ListMember.__subclasses__():
self.stdout.write(f"Cleaning up {cls}...")
cls.objects.filter(visibility=99).delete()
for pcls in [Content, ListMember]:
for cls in pcls.__subclasses__():
self.stdout.write(f"Cleaning up {cls}...")
cls.objects.filter(visibility=99).delete()
self.stdout.write(self.style.SUCCESS(f"Done."))