32 рядки
955 B
Python
32 рядки
955 B
Python
from django.db.models.signals import pre_delete, post_delete, post_save
|
|
from django.dispatch import receiver
|
|
from .models import Task, Project, Comment
|
|
from mycreole import delete_attachment_target_path
|
|
from .search import load_index, delete_item, update_item
|
|
|
|
|
|
@receiver(pre_delete, sender=Task)
|
|
@receiver(pre_delete, sender=Project)
|
|
@receiver(pre_delete, sender=Comment)
|
|
def item_cache_delete(instance, **kwargs):
|
|
delete_attachment_target_path(instance.attachment_target_path)
|
|
|
|
|
|
@receiver(post_delete, sender=Task)
|
|
def search_index_item_delete(instance, **kwargs):
|
|
# delete index entry
|
|
ix = load_index()
|
|
delete_item(ix, instance)
|
|
|
|
|
|
@receiver(post_save, sender=Task)
|
|
@receiver(post_save, sender=Comment)
|
|
@receiver(post_delete, sender=Comment)
|
|
def search_index_item_update(instance, **kwargs):
|
|
if type(instance) == Comment:
|
|
task = instance.task
|
|
else:
|
|
task = instance
|
|
ix = load_index()
|
|
update_item(ix, task)
|