Skip to content

Commit

Permalink
Merge branch 'main' into task/GH-157-frontera-redesign-0
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleyboar committed Apr 14, 2021
2 parents c83ec24 + 2781c7e commit dab9daa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions taccsite_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,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
31 changes: 31 additions & 0 deletions taccsite_cms/signal_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from haystack.signals import BaseSignalProcessor
from django.db import models
from django.core.management import call_command
from cms import signals


class RealtimeSignalProcessor(BaseSignalProcessor):
"""
A signal processor to make a call to the Django Haystack
`rebuild_index` management command when a CMS document is
published, unpublished, or deleted. This will allow the
ElasticSearch index to remain up-to-date with the latest
published CMS content when a user searches the site.
Usage:
This signal processor hooks into Haystack via the
`HAYSTACK_SIGNAL_PROCESSOR` Django setting.
"""

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')
2 changes: 1 addition & 1 deletion taccsite_custom

0 comments on commit dab9daa

Please sign in to comment.