]> git.parisson.com Git - teleforma.git/commitdiff
add cleanup command for private docs
authorGuillaume Pellerin <guillaume.pellerin@parisson.com>
Mon, 13 Jul 2026 21:50:28 +0000 (23:50 +0200)
committerGuillaume Pellerin <guillaume.pellerin@parisson.com>
Mon, 13 Jul 2026 21:50:28 +0000 (23:50 +0200)
teleforma/management/commands/teleforma-delete-year-private-documents.py [new file with mode: 0644]

diff --git a/teleforma/management/commands/teleforma-delete-year-private-documents.py b/teleforma/management/commands/teleforma-delete-year-private-documents.py
new file mode 100644 (file)
index 0000000..8bea5fe
--- /dev/null
@@ -0,0 +1,25 @@
+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.models import DocumentPrivate
+
+
+class Command(BaseCommand):
+    help = "Delete all private docs 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)
+        docs = DocumentPrivate.objects.filter(date_added__lte=date)
+        for doc in docs:
+            doc.delete()
+        
\ No newline at end of file