Django Library PaTT
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.

12345678910111213141516171819202122232425262728293031
  1. from django.db.models.signals import pre_delete, post_delete, post_save
  2. from django.dispatch import receiver
  3. from .models import Task, Project, Comment
  4. from mycreole import delete_attachment_target_path
  5. from .search import load_index, delete_item, update_item
  6. @receiver(pre_delete, sender=Task)
  7. @receiver(pre_delete, sender=Project)
  8. @receiver(pre_delete, sender=Comment)
  9. def item_cache_delete(instance, **kwargs):
  10. delete_attachment_target_path(instance.attachment_target_path)
  11. @receiver(post_delete, sender=Task)
  12. def search_index_item_delete(instance, **kwargs):
  13. # delete index entry
  14. ix = load_index()
  15. delete_item(ix, instance)
  16. @receiver(post_save, sender=Task)
  17. @receiver(post_save, sender=Comment)
  18. @receiver(post_delete, sender=Comment)
  19. def search_index_item_update(instance, **kwargs):
  20. if type(instance) == Comment:
  21. task = instance.task
  22. else:
  23. task = instance
  24. ix = load_index()
  25. update_item(ix, task)