diff --git a/cfgov/search/elasticsearch_helpers.py b/cfgov/search/elasticsearch_helpers.py index f5c79a0916..18e44de910 100644 --- a/cfgov/search/elasticsearch_helpers.py +++ b/cfgov/search/elasticsearch_helpers.py @@ -181,22 +181,28 @@ class WagtailSignalProcessor(BaseSignalProcessor): Wagtail events and calls the appropriate signals to update the search index. - It also translates the `instance` object that gets passed by Wagtail - signal handlers into its `instance.specific` equivalent for any - downstream logic that depends on the specific page type. + It also translates the `instance` Page object that gets passed by Wagtail + signal handlers into its AbstractFilterPage equivalent (if it so inherits) + to ensure that the filterable page search index is properly updated. """ - def handle_delete(self, sender, instance, **kwargs): - if isinstance(instance, Page): - instance = instance.specific + def check_afp(self, instance): + # If the provided instance is a Wagtail page instance that inherits + # from AbstractFilterPage, convert it to an AFP instance. + from v1.models import AbstractFilterPage - super().handle_delete(sender, instance, **kwargs) + if isinstance(instance, Page) and issubclass( + instance.specific_class, AbstractFilterPage + ): + instance = AbstractFilterPage.objects.get(pk=instance.pk) - def handle_save(self, sender, instance, **kwargs): - if isinstance(instance, Page): - instance = instance.specific + return instance - super().handle_save(sender, instance, **kwargs) + def handle_delete(self, sender, instance, **kwargs): + super().handle_delete(sender, self.check_afp(instance), **kwargs) + + def handle_save(self, sender, instance, **kwargs): + super().handle_save(sender, self.check_afp(instance), **kwargs) def setup(self): page_published.connect(self.handle_save) diff --git a/cfgov/v1/documents.py b/cfgov/v1/documents.py index c3391c3451..9080b11617 100644 --- a/cfgov/v1/documents.py +++ b/cfgov/v1/documents.py @@ -38,6 +38,12 @@ class FilterablePagesDocument(Document): products = fields.KeywordField() content = fields.TextField() + def update(self, thing, *args, **kwargs): + if isinstance(thing, AbstractFilterPage): + thing = thing.specific + + return super().update(thing, *args, **kwargs) + def get_queryset(self, *args, **kwargs): return AbstractFilterPage.objects.live().public().specific()