Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Fix/root page issue #51

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/wagtailbakery/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

logger = logging.getLogger(__name__)

BAKERY_RESULTS_PER_PAGE = getattr(settings, 'BAKERY_RESULTS_PER_PAGE', 20)


class APIResponseError(Exception):
pass
Expand All @@ -24,7 +26,7 @@ def handle_api_error(response):


class APIListingView(BuildableMixin):
results_per_page = 20
results_per_page = BAKERY_RESULTS_PER_PAGE

@property
def build_method(self):
Expand Down Expand Up @@ -85,7 +87,7 @@ def build_object(self, obj):
self.build_file(path, page_content)

def build_queryset(self):
[self.build_object(o) for o in self.get_queryset().all()]
[self.build_object(o) for o in self.get_queryset()]

def unbuild_object(self, obj):
"""
Expand Down Expand Up @@ -124,7 +126,7 @@ def get_build_path(self, page):

def get_queryset(self):
if getattr(settings, 'BAKERY_MULTISITE', False):
return Page.objects.all().public().live()
return Page.objects.filter(depth__gt=1).public().live()
else:
site = Site.objects.get(is_default_site=True)
return site.root_page.get_descendants(inclusive=True).public().live()
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
DEFAULT_PAGE_META_FIELDS = {'type', 'show_in_menus', 'search_description', 'first_published_at', 'slug', 'html_url', 'seo_title'}


@pytest.mark.django_db
def test_wagtail_bakery_pages_api_detail_view_contains_no_root_pages():
"""
Do not include the Root page
"""
view = PagesAPIDetailView()
assert not any(o for o in view.get_queryset() if o.depth <= 1)


@pytest.mark.django_db
def test_wagtail_bakery_pages_api_detail_view(page_tree):
view = PagesAPIDetailView()
Expand Down