##// END OF EJS Templates
Added command to remove user and poster ip from all posts
neko259 -
r727:8770d57b default
parent child Browse files
Show More
@@ -1,29 +1,16 b''
1 from datetime import datetime, timedelta
2 from django.core.management import BaseCommand
1 from django.core.management import BaseCommand
3 from django.db import transaction
2 from django.db import transaction
4 from django.db.models import Count
3
5 from boards.models import User, Post
4 from boards.models import Post
5 from boards.models.post import NO_IP
6
6
7
7 __author__ = 'neko259'
8 __author__ = 'neko259'
8
9
9 OLD_USER_AGE_DAYS = 90
10
11
10
12 class Command(BaseCommand):
11 class Command(BaseCommand):
13 help = 'Removes empty users (that don\'t have posts or tags'
12 help = 'Removes user and IP data from all posts'
14
13
15 @transaction.atomic
14 @transaction.atomic
16 def handle(self, *args, **options):
15 def handle(self, *args, **options):
17 old_registration_date = datetime.now().date() - timedelta(
16 Post.objects.all().update(poster_ip=NO_IP, user=None) No newline at end of file
18 OLD_USER_AGE_DAYS)
19
20 old_users = User.objects.annotate(tags_count=Count('fav_tags')).filter(
21 tags_count=0).filter(registration_time__lt=old_registration_date)
22 deleted_users = 0
23 for user in old_users:
24 if not Post.objects.filter(user=user).exists():
25 self.stdout.write('Deleting user %s' % user.user_id)
26 user.delete()
27 deleted_users += 1
28
29 self.stdout.write('Deleted %d users' % deleted_users) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now