Mercurial > public > sg101
annotate ygroup/management/commands/sync_ygroup_threads.py @ 917:0365fdbb4d78
Fix app conflict with messages.
Django's messages app label conflicts with our messages app.
We can't easily rename our label as that will make us rename database tables.
Since our app came first we'll just customize Django messages label.
For Django 1.7.7 upgrade.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 06 Apr 2015 20:02:25 -0500 |
parents | ee87ea74d46b |
children |
rev | line source |
---|---|
bgneal@323 | 1 """ |
bgneal@323 | 2 sync_ygroup_threads.py - A management command to synchronize the yahoo group |
bgneal@323 | 3 archives by recomputing the de-normalized fields in the thread objects. |
bgneal@323 | 4 |
bgneal@323 | 5 """ |
bgneal@323 | 6 import optparse |
bgneal@323 | 7 |
bgneal@323 | 8 from django.core.management.base import NoArgsCommand, CommandError |
bgneal@323 | 9 |
bgneal@323 | 10 from ygroup.models import Thread, Post |
bgneal@323 | 11 import ygroup.views |
bgneal@323 | 12 |
bgneal@323 | 13 |
bgneal@323 | 14 class Command(NoArgsCommand): |
bgneal@323 | 15 help = """\ |
bgneal@323 | 16 This command synchronizes the ygroup application's thread objects |
bgneal@323 | 17 by updating their de-normalized fields. |
bgneal@323 | 18 """ |
bgneal@323 | 19 option_list = NoArgsCommand.option_list + ( |
bgneal@323 | 20 optparse.make_option("-p", "--progress", action="store_true", |
bgneal@323 | 21 help="Output a . after every 50 threads to show progress"), |
bgneal@323 | 22 ) |
bgneal@323 | 23 |
bgneal@323 | 24 def handle_noargs(self, **opts): |
bgneal@323 | 25 |
bgneal@323 | 26 show_progress = opts.get('progress', False) or False |
bgneal@323 | 27 |
bgneal@323 | 28 n = 0 |
bgneal@323 | 29 for thread in Thread.objects.iterator(): |
bgneal@323 | 30 thread.post_count = Post.objects.filter(thread=thread).count() |
bgneal@323 | 31 thread.page = n / ygroup.views.THREADS_PER_PAGE + 1 |
bgneal@323 | 32 thread.save() |
bgneal@323 | 33 n += 1 |
bgneal@323 | 34 if n % 50 == 0: |
bgneal@323 | 35 self.stdout.write('.') |
bgneal@323 | 36 self.stdout.flush() |
bgneal@323 | 37 |
bgneal@323 | 38 self.stdout.write('\n') |
bgneal@323 | 39 |