bgneal@323: """ bgneal@323: sync_ygroup_threads.py - A management command to synchronize the yahoo group bgneal@323: archives by recomputing the de-normalized fields in the thread objects. bgneal@323: bgneal@323: """ bgneal@323: import optparse bgneal@323: bgneal@323: from django.core.management.base import NoArgsCommand, CommandError bgneal@323: bgneal@323: from ygroup.models import Thread, Post bgneal@323: import ygroup.views bgneal@323: bgneal@323: bgneal@323: class Command(NoArgsCommand): bgneal@323: help = """\ bgneal@323: This command synchronizes the ygroup application's thread objects bgneal@323: by updating their de-normalized fields. bgneal@323: """ bgneal@323: option_list = NoArgsCommand.option_list + ( bgneal@323: optparse.make_option("-p", "--progress", action="store_true", bgneal@323: help="Output a . after every 50 threads to show progress"), bgneal@323: ) bgneal@323: bgneal@323: def handle_noargs(self, **opts): bgneal@323: bgneal@323: show_progress = opts.get('progress', False) or False bgneal@323: bgneal@323: n = 0 bgneal@323: for thread in Thread.objects.iterator(): bgneal@323: thread.post_count = Post.objects.filter(thread=thread).count() bgneal@323: thread.page = n / ygroup.views.THREADS_PER_PAGE + 1 bgneal@323: thread.save() bgneal@323: n += 1 bgneal@323: if n % 50 == 0: bgneal@323: self.stdout.write('.') bgneal@323: self.stdout.flush() bgneal@323: bgneal@323: self.stdout.write('\n') bgneal@323: