fixcategoriestree.py 872 B

1234567891011121314151617181920212223
  1. from django.core.management.base import BaseCommand
  2. from misago.acl.cache import clear as clear_acl_cache
  3. from misago.categories.models import Category
  4. class Command(BaseCommand):
  5. """
  6. This command rebuilds the thread category tree.
  7. It can be useful when the category hierarchy is corrupt due to modifying directly
  8. in the database causing MPTT's nested sets to not align correctly.
  9. A typical case is when injecting default data into the database from outside misago.
  10. """
  11. help = 'Rebuilds the thread category tree'
  12. def handle(self, *args, **options):
  13. root = Category.objects.root_category()
  14. Category.objects.partial_rebuild(root.tree_id)
  15. self.stdout.write("Categories tree has been rebuild.")
  16. Category.objects.clear_cache()
  17. clear_acl_cache()
  18. self.stdout.write("Caches have been cleared.")