Django Library PyGal
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

rebuild_cache.py 1.2KB

12345678910111213141516171819202122232425
  1. from django.conf import settings
  2. from django.core.management.base import BaseCommand
  3. import fstools
  4. import pygal
  5. from pygal.models import Item, TYPE_FOLDER, get_item_by_rel_path
  6. class Command(BaseCommand):
  7. def handle(self, *args, **options):
  8. # rebuild existing non folder items
  9. #
  10. for item in Item.objects.all().exclude(type=TYPE_FOLDER):
  11. item.__set_model_fields_from_file__()
  12. item.save()
  13. # rebuild folder items based on file system structure (not existing items will be created)
  14. folder_list = fstools.dirlist(settings.ITEM_ROOT, rekursive=True)
  15. folder_list.append(settings.ITEM_ROOT)
  16. folder_list.sort(reverse=True)
  17. for full_path in folder_list:
  18. item = get_item_by_rel_path(pygal.get_rel_path(full_path))
  19. if item is not None:
  20. item.__set_model_fields_from_file__()
  21. item.save()
  22. self.stdout.write(self.style.SUCCESS('Updated cached data of %d items.' % len(Item.objects.all().exclude(type=TYPE_FOLDER))))
  23. self.stdout.write(self.style.SUCCESS('Updated cached data of %d folders.' % len(Item.objects.filter(type=TYPE_FOLDER))))