##// END OF EJS Templates
Code cleanup. Update only edited fields while performing thread archiving or post editing. Remove image when post is removed
Code cleanup. Update only edited fields while performing thread archiving or post editing. Remove image when post is removed

File last commit:

r689:3d81370e 1.8-dev
r715:056b308f 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)