From d29ca1327f69ffab694f3cb4a13bd97670b970b8 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 13 Jul 2026 23:50:28 +0200 Subject: [PATCH] add cleanup command for private docs --- ...teleforma-delete-year-private-documents.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 teleforma/management/commands/teleforma-delete-year-private-documents.py 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 index 00000000..8bea5fed --- /dev/null +++ b/teleforma/management/commands/teleforma-delete-year-private-documents.py @@ -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 -- 2.47.3