Django Library PyGal
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

signals.py 1.0KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from django.db.models.signals import post_save
  2. from django.db.models.signals import post_delete
  3. from django.dispatch import receiver
  4. import logging
  5. from .models import Item, Tag
  6. from .search import load_index, delete_item, update_item
  7. import shutil
  8. from .views.xnail import base_item
  9. # Get a logger instance
  10. clogger = logging.getLogger("CACHING")
  11. __pre_remove__ = None
  12. __pre_add__ = None
  13. @receiver(post_delete, sender=Item)
  14. def item_delete(instance, **kwargs):
  15. # delete cached xnails
  16. clogger.info('Deleting Xnails stored in "%s".', base_item.__cache_image_folder__(None, instance.rel_path))
  17. shutil.rmtree(base_item.__cache_image_folder__(None, instance.rel_path), True)
  18. # delete index entry
  19. ix = load_index()
  20. delete_item(ix, instance)
  21. @receiver(post_save, sender=Item)
  22. def item_save(instance, **kwargs):
  23. ix = load_index()
  24. update_item(ix, instance)
  25. @receiver(post_save, sender=Tag)
  26. @receiver(post_delete, sender=Tag)
  27. def tag_change(instance, **kwargs):
  28. ix = load_index()
  29. update_item(ix, instance.item)