]> git.parisson.com Git - teleforma.git/commitdiff
delete script by year command
authorGuillaume Pellerin <guillaume.pellerin@free.fr>
Fri, 12 Jul 2024 09:18:22 +0000 (11:18 +0200)
committerGuillaume Pellerin <guillaume.pellerin@free.fr>
Fri, 12 Jul 2024 09:18:22 +0000 (11:18 +0200)
teleforma/management/commands/teleforma-delete-year-scripts.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-delete-year-scripts.py b/teleforma/management/commands/teleforma-delete-year-scripts.py
new file mode 100644 (file)
index 0000000..eb7be41
--- /dev/null
@@ -0,0 +1,26 @@
+import os
+import datetime
+from optparse import make_option
+from django.conf import settings
+from django.core.management.base import BaseCommand, CommandError
+from django.contrib.auth.models import User
+from django.template.defaultfilters import slugify
+from teleforma.exam.models import Script
+
+
+class Command(BaseCommand):
+    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):
+        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()
+        
\ No newline at end of file