Django Library PyGal
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728
  1. from django.core.management.base import BaseCommand
  2. import os
  3. import pygal
  4. from pygal.models import Item
  5. class Command(BaseCommand):
  6. def handle(self, *args, **options):
  7. lil = self.lost_item_list()
  8. if len(lil) == 0:
  9. self.stdout.write(self.style.SUCCESS('No lost items. Nothing to delete.'))
  10. else:
  11. self.stdout.write(self.style.WARNING('Lost Items:'))
  12. for item in lil:
  13. self.stdout.write(self.style.WARNING(' - %s' % str(item)))
  14. response = input('Delete the listed items and all data inside permanently? [y/N]: ')
  15. if response.lower() == 'y':
  16. self.stdout.write(self.style.SUCCESS('Deleting Items:'))
  17. for item in lil:
  18. item.delete()
  19. self.stdout.write(self.style.SUCCESS(' - Deleted: %s' % str(item)))
  20. def lost_item_list(self):
  21. lil = []
  22. for i in Item.objects.all():
  23. if not os.path.exists(pygal.get_full_path(i.rel_path)):
  24. lil.append(i)
  25. return lil