Skip to content

Commit

Permalink
Additional signals (#7)
Browse files Browse the repository at this point in the history
* fix deleteing pages with streamfieldindex
  • Loading branch information
Ross-Clark authored Aug 7, 2024
1 parent 1850b7c commit 61c0c05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions streamfieldindex/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions streamfieldindex/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)


Expand All @@ -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)
8 changes: 4 additions & 4 deletions tests/testapp/urls.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 61c0c05

Please sign in to comment.