From: Guillaume Pellerin Date: Fri, 12 Jul 2024 08:58:34 +0000 (+0200) Subject: add script delete command X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=05fe14b86bc74b3979989ded5c36c42fed243493;p=teleforma.git add script delete command --- diff --git a/teleforma/management/commands/teleforma-delete-period-scripts.py b/teleforma/management/commands/teleforma-delete-period-scripts.py new file mode 100644 index 00000000..d1086a9d --- /dev/null +++ b/teleforma/management/commands/teleforma-delete-period-scripts.py @@ -0,0 +1,25 @@ +import os +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 for a given period" + args = "period_name" + 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) + for script in scripts: + os.remove(script.file.path) + script.delete() + \ No newline at end of file