diff --git a/streamfieldindex/indexer.py b/streamfieldindex/indexer.py index edd81e0..f5923cd 100644 --- a/streamfieldindex/indexer.py +++ b/streamfieldindex/indexer.py @@ -18,6 +18,10 @@ def index_all(page_query=None): index_page(page) +def clear_index(page): + IndexEntry.objects.filter(page__id=page.id).delete() + + def index_page(page): # Clear the index for this specific page diff --git a/streamfieldindex/wagtail_hooks.py b/streamfieldindex/wagtail_hooks.py index c4233a4..18bc98d 100644 --- a/streamfieldindex/wagtail_hooks.py +++ b/streamfieldindex/wagtail_hooks.py @@ -3,7 +3,7 @@ from wagtail.admin.admin_url_finder import ModelAdminURLFinder, register_admin_url_finder from wagtail.signals import page_published, page_unpublished, post_page_move -from .indexer import index_page +from .indexer import clear_index, index_page from .models import IndexEntry @@ -22,15 +22,15 @@ def index_after_copy_page(request, page): index_page(page) -def post_publish(sender, instance, **kwargs): - index_page(instance) +def index_unpublished(sender, instance, **kwargs): + clear_index(instance) -def index_post_page_move(sender, instance, **kwargs): +def post_publish(sender, instance, **kwargs): index_page(instance) -def index_post_unpublished(sender, instance, **kwargs): +def index_post_page_move(sender, instance, **kwargs): index_page(instance) @@ -47,5 +47,5 @@ def construct_edit_url(self, instance): register_admin_url_finder(IndexEntry, IndexEntryAdminURLFinder) page_published.connect(post_publish) -page_unpublished.connect(index_post_unpublished) +page_unpublished.connect(index_unpublished) post_page_move.connect(index_post_page_move) diff --git a/tests/testapp/urls.py b/tests/testapp/urls.py index 9c5f127..0942755 100644 --- a/tests/testapp/urls.py +++ b/tests/testapp/urls.py @@ -1,14 +1,14 @@ from django.conf import settings from django.contrib import admin -from django.urls import include, path +from django.urls import include, path, re_path from wagtail import urls as wagtail_urls from wagtail.admin import urls as wagtailadmin_urls from wagtail.documents import urls as wagtaildocs_urls urlpatterns = [ - path(r"^django-admin/", admin.site.urls), - path(r"^admin/", include(wagtailadmin_urls)), - path(r"^documents/", include(wagtaildocs_urls)), + re_path(r"^django-admin/", admin.site.urls), + re_path(r"^admin/", include(wagtailadmin_urls)), + re_path(r"^documents/", include(wagtaildocs_urls)), ] if settings.DEBUG: