Mercurial > public > sg101
comparison gpp/ygroup/management/commands/sync_ygroup_threads.py @ 323:0c18dfb1da1c
Fixing #149; adding the ygroup application: an archive of the old Yahoo Group messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 20 Feb 2011 00:31:54 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
322:c3d3d7114749 | 323:0c18dfb1da1c |
---|---|
1 """ | |
2 sync_ygroup_threads.py - A management command to synchronize the yahoo group | |
3 archives by recomputing the de-normalized fields in the thread objects. | |
4 | |
5 """ | |
6 import optparse | |
7 | |
8 from django.core.management.base import NoArgsCommand, CommandError | |
9 | |
10 from ygroup.models import Thread, Post | |
11 import ygroup.views | |
12 | |
13 | |
14 class Command(NoArgsCommand): | |
15 help = """\ | |
16 This command synchronizes the ygroup application's thread 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 threads 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 thread in Thread.objects.iterator(): | |
30 thread.post_count = Post.objects.filter(thread=thread).count() | |
31 thread.page = n / ygroup.views.THREADS_PER_PAGE + 1 | |
32 thread.save() | |
33 n += 1 | |
34 if n % 50 == 0: | |
35 self.stdout.write('.') | |
36 self.stdout.flush() | |
37 | |
38 self.stdout.write('\n') | |
39 |