From 31a6d2a88f2ddf045df8cd10d232d2215fad2f3a Mon Sep 17 00:00:00 2001 From: Ross Crawford-d'Heureuse Date: Thu, 2 Jan 2020 14:37:22 +0100 Subject: [PATCH 1/6] excldude root page for api renderer --- src/wagtailbakery/api_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wagtailbakery/api_views.py b/src/wagtailbakery/api_views.py index a2bbed8..e7bd970 100644 --- a/src/wagtailbakery/api_views.py +++ b/src/wagtailbakery/api_views.py @@ -85,7 +85,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().all() if o.is_root() is False] def unbuild_object(self, obj): """ From 823dadc706c7b9ab552dd2bba4e976534da497ce Mon Sep 17 00:00:00 2001 From: Ross Crawford-d'Heureuse Date: Thu, 2 Jan 2020 14:39:17 +0100 Subject: [PATCH 2/6] added BAKERY_RESULTS_PER_PAGE --- src/wagtailbakery/api_views.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/wagtailbakery/api_views.py b/src/wagtailbakery/api_views.py index e7bd970..ec6ba60 100644 --- a/src/wagtailbakery/api_views.py +++ b/src/wagtailbakery/api_views.py @@ -1,16 +1,20 @@ +import os import json import logging -import os -from bakery.views import BuildableMixin from django.conf import settings -from django.contrib.contenttypes.models import ContentType -from wagtail.api.v2.endpoints import PagesAPIEndpoint -from wagtail.api.v2.router import WagtailAPIRouter +from bakery.views import BuildableMixin + from wagtail.core.models import Page, Site +from wagtail.api.v2.router import WagtailAPIRouter +from wagtail.api.v2.endpoints import PagesAPIEndpoint + +from django.contrib.contenttypes.models import ContentType logger = logging.getLogger(__name__) +BAKERY_RESULTS_PER_PAGE = getattr(settings, 'BAKERY_RESULTS_PER_PAGE', 25) + class APIResponseError(Exception): pass @@ -24,7 +28,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): From 1db0e21ea9be89aea667709dfc2eefdade798260 Mon Sep 17 00:00:00 2001 From: Ross Crawford-d'Heureuse Date: Thu, 2 Jan 2020 16:08:53 +0100 Subject: [PATCH 3/6] notes from @zerolab --- src/wagtailbakery/api_views.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/wagtailbakery/api_views.py b/src/wagtailbakery/api_views.py index ec6ba60..f992d8e 100644 --- a/src/wagtailbakery/api_views.py +++ b/src/wagtailbakery/api_views.py @@ -1,19 +1,17 @@ -import os import json import logging +import os -from django.conf import settings from bakery.views import BuildableMixin - -from wagtail.core.models import Page, Site -from wagtail.api.v2.router import WagtailAPIRouter -from wagtail.api.v2.endpoints import PagesAPIEndpoint - +from django.conf import settings from django.contrib.contenttypes.models import ContentType +from wagtail.api.v2.endpoints import PagesAPIEndpoint +from wagtail.api.v2.router import WagtailAPIRouter +from wagtail.core.models import Page, Site logger = logging.getLogger(__name__) -BAKERY_RESULTS_PER_PAGE = getattr(settings, 'BAKERY_RESULTS_PER_PAGE', 25) +BAKERY_RESULTS_PER_PAGE = getattr(settings, 'BAKERY_RESULTS_PER_PAGE', 20) class APIResponseError(Exception): From c72a05aff92dc4d5531df1397ab2cc5b17eea84d Mon Sep 17 00:00:00 2001 From: Ross Crawford-d'Heureuse Date: Thu, 2 Jan 2020 16:09:45 +0100 Subject: [PATCH 4/6] more efficient selector excluding root --- src/wagtailbakery/api_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wagtailbakery/api_views.py b/src/wagtailbakery/api_views.py index f992d8e..a2890cb 100644 --- a/src/wagtailbakery/api_views.py +++ b/src/wagtailbakery/api_views.py @@ -87,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() if o.is_root() is False] + [self.build_object(o) for o in self.get_queryset().filter(depth__gt=1)] def unbuild_object(self, obj): """ From e4860eb6cfc596a9247b996d78982cf5c9e8c87e Mon Sep 17 00:00:00 2001 From: Ross Crawford-d'Heureuse Date: Thu, 2 Jan 2020 16:38:59 +0100 Subject: [PATCH 5/6] Added basic test --- src/wagtailbakery/api_views.py | 4 ++-- tests/integration/test_api_views.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/wagtailbakery/api_views.py b/src/wagtailbakery/api_views.py index a2890cb..6f8b918 100644 --- a/src/wagtailbakery/api_views.py +++ b/src/wagtailbakery/api_views.py @@ -87,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().filter(depth__gt=1)] + [self.build_object(o) for o in self.get_queryset()] def unbuild_object(self, obj): """ @@ -126,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..837c900 100644 --- a/tests/integration/test_api_views.py +++ b/tests/integration/test_api_views.py @@ -11,6 +11,14 @@ 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() From 28ae53756c7a0da3106411d969036fb2e3968b5b Mon Sep 17 00:00:00 2001 From: Ross Crawford-d'Heureuse Date: Thu, 2 Jan 2020 16:43:17 +0100 Subject: [PATCH 6/6] travis lint fix --- tests/integration/test_api_views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/test_api_views.py b/tests/integration/test_api_views.py index 837c900..5f64ebc 100644 --- a/tests/integration/test_api_views.py +++ b/tests/integration/test_api_views.py @@ -19,6 +19,7 @@ def test_wagtail_bakery_pages_api_detail_view_contains_no_root_pages(): 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()