diff --git a/src/wagtailbakery/api_views.py b/src/wagtailbakery/api_views.py index a2bbed8..6f8b918 100644 --- a/src/wagtailbakery/api_views.py +++ b/src/wagtailbakery/api_views.py @@ -11,6 +11,8 @@ logger = logging.getLogger(__name__) +BAKERY_RESULTS_PER_PAGE = getattr(settings, 'BAKERY_RESULTS_PER_PAGE', 20) + class APIResponseError(Exception): pass @@ -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): @@ -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): """ @@ -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() diff --git a/tests/integration/test_api_views.py b/tests/integration/test_api_views.py index 18d3319..5f64ebc 100644 --- a/tests/integration/test_api_views.py +++ b/tests/integration/test_api_views.py @@ -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()