Source

lfs-solr / lfs_solr / listeners.py

# django imports
from django.db.models.signals import post_save
from django.db.models.signals import post_delete

# lfs imports
from lfs.catalog.models import Product

# lfs_solr imports
from lfs_solr.utils import index_product
from lfs_solr.utils import delete_product
from lfs_solr.utils import SOLR_ENABLED


def product_deleted_listener(sender, instance, **kwargs):
    if SOLR_ENABLED:
        delete_product(instance)
post_delete.connect(product_deleted_listener, sender=Product)


def product_saved_listener(sender, instance, **kwargs):
    if SOLR_ENABLED:
        if instance.is_active():
            index_product(instance)
        else:
            delete_product(instance)
post_save.connect(product_saved_listener, sender=Product)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.