From: Guillaume Pellerin Date: Mon, 13 Jul 2026 21:50:28 +0000 (+0200) Subject: add cleanup command for private docs X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=d29ca1327f69ffab694f3cb4a13bd97670b970b8;p=teleforma.git add cleanup command for private docs --- 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