##// END OF EJS Templates
Moved imageboard settings to the boards settings module. Added setting to disable archive
Moved imageboard settings to the boards settings module. Added setting to disable archive

File last commit:

r689:3d81370e 1.8-dev
r716:a6b9dd95 1.8.1 default
Show More
cleanusers.py
28 lines | 972 B | text/x-python | PythonLexer
from datetime import datetime, timedelta
from django.core.management import BaseCommand
from django.db import transaction
from django.db.models import Count
from boards.models import User, Post
__author__ = 'neko259'
OLD_USER_AGE_DAYS = 90
class Command(BaseCommand):
help = 'Removes empty users (that don\'t have posts or tags'
@transaction.atomic
def handle(self, *args, **options):
old_registration_date = datetime.now().date() - timedelta(
OLD_USER_AGE_DAYS)
old_users = User.objects.annotate(tags_count=Count('fav_tags')).filter(
tags_count=0).filter(registration_time__lt=old_registration_date)
deleted_users = 0
for user in old_users:
if not Post.objects.filter(user=user).exists():
self.stdout.write('Deleting user %s' % user.user_id)
user.delete()
deleted_users += 1
self.stdout.write('Deleted %d users' % deleted_users)