Mercurial > public > sg101
comparison gpp/forums/management/commands/sync_forums.py @ 294:254db4cb6a86
Changes / scripts to import forums. Other tweaks and moving other import scripts to the legacy application.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 05 Jan 2011 04:09:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
293:c92fb89dbc7d | 294:254db4cb6a86 |
---|---|
1 """ | |
2 sync_forums.py - A management command to synchronize the forums by recomputing | |
3 the de-normalized fields in the forum and topic objects. | |
4 | |
5 """ | |
6 import optparse | |
7 | |
8 from django.core.management.base import NoArgsCommand, CommandError | |
9 | |
10 from forums.models import Forum | |
11 from forums.models import Topic | |
12 | |
13 | |
14 class Command(NoArgsCommand): | |
15 help = """\ | |
16 This command synchronizes the forum application's forums and topic objects | |
17 by updating their de-normalized fields. | |
18 """ | |
19 option_list = NoArgsCommand.option_list + ( | |
20 optparse.make_option("-p", "--progress", action="store_true", | |
21 help="Output a . after every 50 topics to show progress"), | |
22 ) | |
23 | |
24 def handle_noargs(self, **opts): | |
25 | |
26 show_progress = opts.get('progress', False) or False | |
27 | |
28 n = 0 | |
29 for topic in Topic.objects.iterator(): | |
30 topic.post_count_update() | |
31 topic.save() | |
32 n += 1 | |
33 if n % 50 == 0: | |
34 self.stdout.write('.') | |
35 self.stdout.flush() | |
36 | |
37 for forum in Forum.objects.all(): | |
38 forum.sync() | |
39 forum.save() | |
40 | |
41 self.stdout.write('\n') | |
42 |