from wagtail.core import hooks

from .models import ContentBlock


@hooks.register('construct_explorer_page_queryset')
def remove_user_created_content_blocks_from_menu(parent_page, pages, request):
    if parent_page.content_type.model == 'chapter':
        return ContentBlock.get_by_parent(parent_page.specific).exclude(user_created=True)
    return pages
