comparison ygroup/management/commands/sync_ygroup_threads.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/ygroup/management/commands/sync_ygroup_threads.py@0c18dfb1da1c
children
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
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