From: Guillaume Pellerin Date: Fri, 12 Jul 2024 09:07:01 +0000 (+0200) Subject: remove script by year X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=8d8583e15d30a94ebdf64463100da68a3cc57c53;p=teleforma.git remove script by year --- diff --git a/teleforma/management/commands/teleforma-delete-period-scripts.py b/teleforma/management/commands/teleforma-delete-period-scripts.py index d1086a9d..eb7be414 100644 --- a/teleforma/management/commands/teleforma-delete-period-scripts.py +++ b/teleforma/management/commands/teleforma-delete-period-scripts.py @@ -1,4 +1,5 @@ import os +import datetime from optparse import make_option from django.conf import settings from django.core.management.base import BaseCommand, CommandError @@ -8,17 +9,17 @@ from teleforma.exam.models import Script class Command(BaseCommand): - help = "Delete all exam scripts for a given period" - args = "period_name" + help = "Delete all exam scripts older than a given year" + args = "year" admin_email = 'webmaster@parisson.com' def add_arguments(self, parser): parser.add_argument('args', nargs='*') def handle(self, *args, **options): - period_name = args[0] - period = Period.objects.get(name=period_name) - scripts = Script.objects.filter(period=period) + year = int(args[0]) + date = datetime.datetime(day=31, month=12, year=year) + scripts = Script.objects.filter(date_added__lte=date) for script in scripts: os.remove(script.file.path) script.delete()