Skip to content

Commit

Permalink
fix error in unpublishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross-Clark committed Aug 6, 2024
1 parent 781b131 commit 508e826
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 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,16 @@ def index_after_copy_page(request, page):
index_page(page)


def post_publish(sender, instance, **kwargs):
index_page(instance)
@hooks.register("before_unpublish_page")
def index_post_unpublished(request, page):
clear_index(page)


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 +48,4 @@ def construct_edit_url(self, instance):
register_admin_url_finder(IndexEntry, IndexEntryAdminURLFinder)

page_published.connect(post_publish)
page_unpublished.connect(index_post_unpublished)
post_page_move.connect(index_post_page_move)

0 comments on commit 508e826

Please sign in to comment.