|
|
from datetime import datetime, timedelta, date
|
|
|
from datetime import time as dtime
|
|
|
|
|
|
from django.core.management import BaseCommand
|
|
|
from django.db import transaction
|
|
|
from django.utils import timezone
|
|
|
|
|
|
from boards.models import Post
|
|
|
from boards.models.post.manager import NO_IP
|
|
|
|
|
|
__author__ = 'neko259'
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
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.')
|
|
|
|
|
|
@transaction.atomic
|
|
|
def handle(self, *args, **options):
|
|
|
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)
|
|
|
|
|
|
|