from django.db.models import signals
from webcube.searchable.models import update_terms,purge_terms
from models import *

def update_infopage_search(instance,**kwargs):
    if instance.active:
        terms = u' '.join((instance.name,instance.body))
        update_terms(instance,terms=terms)
    else:
        purge_terms(instance)

signals.post_save.connect(update_infopage_search, sender=InfoPage)
signals.post_delete.connect(purge_terms, sender=InfoPage)