Commit 7a55f117 authored by Flavio TARSETTI's avatar Flavio TARSETTI

[accounts][management][commands] Improve expired temporary urls deletion

parent 24fcf0ee
......@@ -57,15 +57,10 @@ class Command(BaseCommand):
self.stdout.write('Clean expired temporary urls operation canceled')
sys.exit(1)
temporary_urls = TemporaryUrl.objects.all()
count = 0
for temporary_url in temporary_urls:
now = datetime.datetime.now()
if temporary_url.expires < now:
count+=1
temporary_url.delete()
self.stdout.write('{} Expired temporary url(s) successfully cleaned/'.format(count) + '{} Total temporary url(s) checked'.format(temporary_urls.count()))
temporary_urls_count = TemporaryUrl.objects.all().count()
now = datetime.datetime.now()
count = TemporaryUrl.objects.filter(expires__lt=now).delete()[0]
self.stdout.write('{} Expired temporary url(s) successfully cleaned/'.format(count) + '{} Total temporary url(s) checked'.format(temporary_urls_count))
def get_input_data(self, message, default=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment