]> git.parisson.com Git - teleforma.git/commitdiff
add command to delete old scripts and annotations
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 22 Jun 2021 07:12:05 +0000 (09:12 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Tue, 22 Jun 2021 07:12:05 +0000 (09:12 +0200)
teleforma/management/commands/teleforma-delete-annotations.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-delete-annotations.py b/teleforma/management/commands/teleforma-delete-annotations.py
new file mode 100644 (file)
index 0000000..81088ce
--- /dev/null
@@ -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