Mercurial > public > sg101
comparison forums/management/commands/sync_forums.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/forums/management/commands/sync_forums.py@254db4cb6a86 |
children |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
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 |