Skip to content

Commit

Permalink
add rebuild_index haystack signal processor
Browse files Browse the repository at this point in the history
  • Loading branch information
rstijerina committed Apr 12, 2021
1 parent 0fd2b8a commit 00f3069
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions taccsite_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def get_subdirs_as_module_names(path):

# Elasticsearch Indexing
HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter',]
HAYSTACK_SIGNAL_PROCESSOR = 'taccsite_cms.signal_processor.RealtimeSignalProcessor'
ALDRYN_SEARCH_DEFAULT_LANGUAGE = 'en'
ALDRYN_SEARCH_REGISTER_APPHOOK = True
HAYSTACK_CONNECTIONS = {
Expand Down
21 changes: 21 additions & 0 deletions taccsite_cms/signal_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from haystack.signals import BaseSignalProcessor
from django.db import models
from cms import signals
from django.core.management import call_command


class RealtimeSignalProcessor(BaseSignalProcessor):

def setup(self):
signals.post_publish.connect(self.handle_save)
signals.post_unpublish.connect(self.handle_save)
models.signals.post_delete.connect(self.handle_save)


def teardown(self):
signals.post_publish.disconnect(self.handle_save)
signals.post_unpublish.disconnect(self.handle_save)
models.signals.post_delete.disconnect(self.handle_save)

def handle_save(self, **kwargs):
call_command('rebuild_index', '--noinput')

0 comments on commit 00f3069

Please sign in to comment.