]> git.parisson.com Git - teleforma.git/commitdiff
remove script by year
authorGuillaume Pellerin <guillaume.pellerin@free.fr>
Fri, 12 Jul 2024 09:07:01 +0000 (11:07 +0200)
committerGuillaume Pellerin <guillaume.pellerin@free.fr>
Fri, 12 Jul 2024 09:07:01 +0000 (11:07 +0200)
teleforma/management/commands/teleforma-delete-period-scripts.py

index d1086a9d3d876a4bbbbb828d8054936208a73456..eb7be414e8526be8dc556d1b5c355f083af870ea 100644 (file)
@@ -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()