synchronizecategories.py 852 B

12345678910111213141516171819202122232425262728
  1. from django.core.management.base import BaseCommand
  2. from misago.core.management.progressbar import show_progress
  3. from ...models import Category
  4. class Command(BaseCommand):
  5. help = 'Synchronizes categories'
  6. def handle(self, *args, **options):
  7. categories_to_sync = Category.objects.count()
  8. message = 'Synchronizing %s categories...\n'
  9. self.stdout.write(message % categories_to_sync)
  10. message = '\n\nSynchronized %s categories'
  11. synchronized_count = 0
  12. show_progress(self, synchronized_count, categories_to_sync)
  13. for category in Category.objects.iterator():
  14. category.synchronize()
  15. category.save()
  16. synchronized_count += 1
  17. show_progress(self, synchronized_count, categories_to_sync)
  18. self.stdout.write(message % synchronized_count)