32 lines
969 B
Python
32 lines
969 B
Python
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.utils import timezone
|
|
|
|
from apps.comments.models import Comment
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Nullify comment personal data for comments older than the retention window."
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
"--months",
|
|
type=int,
|
|
default=24,
|
|
help="Retention window in months before personal data is purged (default: 24).",
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
months = options["months"]
|
|
cutoff = timezone.now() - timedelta(days=30 * months)
|
|
|
|
purged = (
|
|
Comment.objects.filter(created_at__lt=cutoff)
|
|
.exclude(author_email="")
|
|
.update(author_email="", ip_address=None)
|
|
)
|
|
self.stdout.write(self.style.SUCCESS(f"Purged personal data for {purged} comment(s)."))
|