From: Guillaume Pellerin Date: Tue, 22 Jun 2021 07:12:05 +0000 (+0200) Subject: add command to delete old scripts and annotations X-Git-Tag: 2.1~66^2^2~14 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=a5f8f48f1fe9d361919ac74b8a9136c2fbe2d46c;p=teleforma.git add command to delete old scripts and annotations --- diff --git a/teleforma/management/commands/teleforma-delete-annotations.py b/teleforma/management/commands/teleforma-delete-annotations.py new file mode 100644 index 00000000..81088ce6 --- /dev/null +++ b/teleforma/management/commands/teleforma-delete-annotations.py @@ -0,0 +1,31 @@ + +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 jqchat.models import Message +import datetime +from teleforma.exam.models import Script +from pdfannotator.models import Annotation, AnnotationComment + + +class Command(BaseCommand): + help = "Delete script annotations from previous year" + + def handle(self, *args, **options): + date = datetime.datetime.now() + date_old = date_now.replace(year=date_now.year-1, month=12, day=31) + print(date_old) + scripts = Script.objects.filter(date_submitted__lte=date_old) + print(scripts.count()) + + for script in scripts: + annotations = Annotation.objects.filter(uuid=script.uuid) + for annotation in annotations: + annotation.delete() + annotation_comments = AnnotationComment.objects.filter(uuid=script.uuid) + for annotation_comment in annotation_comments: + annotation_comment.delete() + script.delete() + + \ No newline at end of file