Django Library PyGal
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

signals.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from django.conf import settings
  2. from django.db.models.signals import post_save
  3. from django.db.models.signals import post_delete
  4. from django.dispatch import receiver
  5. import logging
  6. from .models import Item, Tag
  7. from .search import load_index, delete_item, update_item
  8. import shutil
  9. from .views.xnail import base_item
  10. logger = logging.getLogger(settings.ROOT_LOGGER_NAME).getChild(__name__)
  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. logger.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)