enforce_privacy.py
34 lines
| 1.0 KiB
| text/x-python
|
PythonLexer
neko259
|
r1864 | from datetime import datetime, timedelta, date | ||
from datetime import time as dtime | ||||
neko259
|
r727 | from django.core.management import BaseCommand | ||
from django.db import transaction | ||||
neko259
|
r1864 | from django.utils import timezone | ||
neko259
|
r727 | |||
from boards.models import Post | ||||
neko259
|
r1234 | from boards.models.post.manager import NO_IP | ||
neko259
|
r727 | |||
__author__ = 'neko259' | ||||
class Command(BaseCommand): | ||||
neko259
|
r1864 | help = 'Removes user and IP data from posts' | ||
def add_arguments(self, parser): | ||||
parser.add_argument('--days-before', type=int, | ||||
help='Clean posts only before the number of days before today.') | ||||
neko259
|
r727 | |||
@transaction.atomic | ||||
def handle(self, *args, **options): | ||||
neko259
|
r1864 | days_before = options.get('days_before') | ||
if days_before: | ||||
day_end = date.today() - timedelta(1) | ||||
day_time_end = timezone.make_aware(datetime.combine( | ||||
day_end, dtime()), timezone.get_current_timezone()) | ||||
posts = Post.objects.filter(pub_time__lte=day_time_end) | ||||
else: | ||||
posts = Post.objects.all() | ||||
posts.update(poster_ip=NO_IP) | ||||