##// END OF EJS Templates
Run js highlight on the new posts only, not on all page each time. Add...
Run js highlight on the new posts only, not on all page each time. Add highlight to the reflink popups

File last commit:

r689:3d81370e 1.8-dev
r709:e6788412 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)