synchronizecategories.py 1.0 KB

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