chore: review empty_trash command (#2360)
Some checks are pending
Test & Docs / tests (postgresql, 3.10) (push) Waiting to run
Test & Docs / tests (postgresql, 3.12) (push) Waiting to run
Test & Docs / lint (push) Waiting to run
Test & Docs / docs (push) Waiting to run

- do not try to print map.id after delete (it's None)
- rely on date instead of minutes/microseconds
This commit is contained in:
Yohan Boniface 2024-12-12 16:32:34 +01:00 committed by GitHub
commit a574db73e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,10 +23,13 @@ class Command(BaseCommand):
def handle(self, *args, **options):
days = options["days"]
since = datetime.utcnow() - timedelta(days=days)
since = (datetime.utcnow() - timedelta(days=days)).date()
print(f"Deleting map in trash since {since}")
maps = Map.objects.filter(share_status=Map.DELETED, modified_at__lt=since)
for map in maps:
map_id = map.id
map_name = map.name
trashed_at = map.modified_at.date()
if not options["dry_run"]:
map.delete()
print(f"Deleted map {map.name} ({map.id}), trashed on {map.modified_at}")
print(f"Deleted map {map_name} ({map_id}), trashed at {trashed_at}")