bgneal@294: """ bgneal@294: sync_forums.py - A management command to synchronize the forums by recomputing bgneal@294: the de-normalized fields in the forum and topic objects. bgneal@294: bgneal@294: """ bgneal@294: import optparse bgneal@294: bgneal@294: from django.core.management.base import NoArgsCommand, CommandError bgneal@294: bgneal@294: from forums.models import Forum bgneal@294: from forums.models import Topic bgneal@294: bgneal@294: bgneal@294: class Command(NoArgsCommand): bgneal@294: help = """\ bgneal@294: This command synchronizes the forum application's forums and topic objects bgneal@294: by updating their de-normalized fields. bgneal@294: """ bgneal@294: option_list = NoArgsCommand.option_list + ( bgneal@294: optparse.make_option("-p", "--progress", action="store_true", bgneal@294: help="Output a . after every 50 topics to show progress"), bgneal@294: ) bgneal@294: bgneal@294: def handle_noargs(self, **opts): bgneal@294: bgneal@294: show_progress = opts.get('progress', False) or False bgneal@294: bgneal@294: n = 0 bgneal@294: for topic in Topic.objects.iterator(): bgneal@294: topic.post_count_update() bgneal@294: topic.save() bgneal@294: n += 1 bgneal@294: if n % 50 == 0: bgneal@294: self.stdout.write('.') bgneal@294: self.stdout.flush() bgneal@294: bgneal@294: for forum in Forum.objects.all(): bgneal@294: forum.sync() bgneal@294: forum.save() bgneal@294: bgneal@294: self.stdout.write('\n') bgneal@294: