From 53093b73b3bb14a6720924842bfdaadf7edfe5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Sat, 19 Aug 2023 06:02:13 +0200 Subject: [PATCH 1/8] Fix bug preventing request.is_preview from being set --- CHANGELOG.md | 2 ++ Company-Project/src/nextjs/api.py | 1 + {{cookiecutter.project_name}}/src/nextjs/api.py | 1 + 3 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9a7e8316..40ca823c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed ### Fixed +- Fix bug preventing request.is_preview from being set + ### Removed ## [8.12.2] - 2023-08-16 diff --git a/Company-Project/src/nextjs/api.py b/Company-Project/src/nextjs/api.py index f70c3bb49..dd99b9b6d 100644 --- a/Company-Project/src/nextjs/api.py +++ b/Company-Project/src/nextjs/api.py @@ -57,6 +57,7 @@ class PagePreviewAPIViewSet(BaseAPIViewSet): def listing_view(self, request): page = self.get_object() + setattr(request, "is_preview", True) return page.serve(request) def get_object(self): diff --git a/{{cookiecutter.project_name}}/src/nextjs/api.py b/{{cookiecutter.project_name}}/src/nextjs/api.py index f70c3bb49..dd99b9b6d 100644 --- a/{{cookiecutter.project_name}}/src/nextjs/api.py +++ b/{{cookiecutter.project_name}}/src/nextjs/api.py @@ -57,6 +57,7 @@ class PagePreviewAPIViewSet(BaseAPIViewSet): def listing_view(self, request): page = self.get_object() + setattr(request, "is_preview", True) return page.serve(request) def get_object(self): From da95d966df61556debd1c738178470d0890b1c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Sat, 19 Aug 2023 06:07:39 +0200 Subject: [PATCH 2/8] Hide wagtail userbar on preview --- CHANGELOG.md | 1 + Company-Project/src/main/pages/base_serializer.py | 4 ++++ .../src/main/pages/base_serializer.py | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40ca823c4..587c1d81d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### Fixed - Fix bug preventing request.is_preview from being set +- Hide wagtail userbar on preview ### Removed diff --git a/Company-Project/src/main/pages/base_serializer.py b/Company-Project/src/main/pages/base_serializer.py index cda0a2d0f..985b297a6 100644 --- a/Company-Project/src/main/pages/base_serializer.py +++ b/Company-Project/src/main/pages/base_serializer.py @@ -47,6 +47,10 @@ def get_wagtail_userbar(self, page): if not request: return None + is_preview = getattr(request, "is_preview", False) + if is_preview: + return None + if not hasattr(request, "user"): return None diff --git a/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py b/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py index cda0a2d0f..985b297a6 100644 --- a/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py +++ b/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py @@ -47,6 +47,10 @@ def get_wagtail_userbar(self, page): if not request: return None + is_preview = getattr(request, "is_preview", False) + if is_preview: + return None + if not hasattr(request, "user"): return None From f6bd9db56c2d2abd9a627ec795fb6170bde8827c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Sat, 19 Aug 2023 06:48:09 +0200 Subject: [PATCH 3/8] Make sure in_preview_panel is set --- CHANGELOG.md | 1 + Company-Project/frontend/pages/_preview.js | 6 ++++-- Company-Project/frontend/pages/api/preview.js | 5 ++++- Company-Project/src/nextjs/api.py | 4 ++++ {{cookiecutter.project_name}}/frontend/pages/_preview.js | 6 ++++-- {{cookiecutter.project_name}}/frontend/pages/api/preview.js | 5 ++++- {{cookiecutter.project_name}}/src/nextjs/api.py | 4 ++++ 7 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 587c1d81d..a08355b50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix bug preventing request.is_preview from being set - Hide wagtail userbar on preview +- Make sure in_preview_panel is set ### Removed diff --git a/Company-Project/frontend/pages/_preview.js b/Company-Project/frontend/pages/_preview.js index c33ac493a..4877ca7bb 100644 --- a/Company-Project/frontend/pages/_preview.js +++ b/Company-Project/frontend/pages/_preview.js @@ -10,14 +10,16 @@ export async function getServerSideProps({ req, preview, previewData }) { return { props: {} }; } - const { contentType, token, host } = previewData; + const { contentType, token, host, inPreviewPanel } = previewData; // TODO: Add proper token verification and error message try { const { json: pagePreviewData } = await getPagePreview( contentType, token, - {}, + { + in_preview_panel: inPreviewPanel, + }, { headers: { cookie: req.headers.cookie, diff --git a/Company-Project/frontend/pages/api/preview.js b/Company-Project/frontend/pages/api/preview.js index 6836b60d8..8950c7d0a 100644 --- a/Company-Project/frontend/pages/api/preview.js +++ b/Company-Project/frontend/pages/api/preview.js @@ -14,8 +14,11 @@ export default async (req, res) => { // return res.status(401).json({ message: 'Invalid slug' }) // } + const referer = req.headers?.referer || "" + const inPreviewPanel = referer.includes("in_preview_panel=true") + res.setPreviewData( - { contentType, token, host }, + { contentType, token, host, inPreviewPanel }, { path: '/_preview', } diff --git a/Company-Project/src/nextjs/api.py b/Company-Project/src/nextjs/api.py index dd99b9b6d..d73f8f402 100644 --- a/Company-Project/src/nextjs/api.py +++ b/Company-Project/src/nextjs/api.py @@ -58,6 +58,10 @@ class PagePreviewAPIViewSet(BaseAPIViewSet): def listing_view(self, request): page = self.get_object() setattr(request, "is_preview", True) + + in_preview_panel = request.GET.get("in_preview_panel", None) == "true" + setattr(request, "in_preview_panel", in_preview_panel) + return page.serve(request) def get_object(self): diff --git a/{{cookiecutter.project_name}}/frontend/pages/_preview.js b/{{cookiecutter.project_name}}/frontend/pages/_preview.js index c33ac493a..4877ca7bb 100644 --- a/{{cookiecutter.project_name}}/frontend/pages/_preview.js +++ b/{{cookiecutter.project_name}}/frontend/pages/_preview.js @@ -10,14 +10,16 @@ export async function getServerSideProps({ req, preview, previewData }) { return { props: {} }; } - const { contentType, token, host } = previewData; + const { contentType, token, host, inPreviewPanel } = previewData; // TODO: Add proper token verification and error message try { const { json: pagePreviewData } = await getPagePreview( contentType, token, - {}, + { + in_preview_panel: inPreviewPanel, + }, { headers: { cookie: req.headers.cookie, diff --git a/{{cookiecutter.project_name}}/frontend/pages/api/preview.js b/{{cookiecutter.project_name}}/frontend/pages/api/preview.js index 6836b60d8..8950c7d0a 100644 --- a/{{cookiecutter.project_name}}/frontend/pages/api/preview.js +++ b/{{cookiecutter.project_name}}/frontend/pages/api/preview.js @@ -14,8 +14,11 @@ export default async (req, res) => { // return res.status(401).json({ message: 'Invalid slug' }) // } + const referer = req.headers?.referer || "" + const inPreviewPanel = referer.includes("in_preview_panel=true") + res.setPreviewData( - { contentType, token, host }, + { contentType, token, host, inPreviewPanel }, { path: '/_preview', } diff --git a/{{cookiecutter.project_name}}/src/nextjs/api.py b/{{cookiecutter.project_name}}/src/nextjs/api.py index dd99b9b6d..d73f8f402 100644 --- a/{{cookiecutter.project_name}}/src/nextjs/api.py +++ b/{{cookiecutter.project_name}}/src/nextjs/api.py @@ -58,6 +58,10 @@ class PagePreviewAPIViewSet(BaseAPIViewSet): def listing_view(self, request): page = self.get_object() setattr(request, "is_preview", True) + + in_preview_panel = request.GET.get("in_preview_panel", None) == "true" + setattr(request, "in_preview_panel", in_preview_panel) + return page.serve(request) def get_object(self): From 8f981c048011ce6cf39293f0c2dcdf70ba01abc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Sat, 19 Aug 2023 06:49:54 +0200 Subject: [PATCH 4/8] Hide wagtail userbar when in preview panel --- CHANGELOG.md | 2 +- Company-Project/src/main/pages/base_serializer.py | 4 ++-- .../src/main/pages/base_serializer.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a08355b50..8f82c9fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### Fixed - Fix bug preventing request.is_preview from being set -- Hide wagtail userbar on preview +- Hide wagtail userbar when in preview panel - Make sure in_preview_panel is set ### Removed diff --git a/Company-Project/src/main/pages/base_serializer.py b/Company-Project/src/main/pages/base_serializer.py index 985b297a6..cec2455b8 100644 --- a/Company-Project/src/main/pages/base_serializer.py +++ b/Company-Project/src/main/pages/base_serializer.py @@ -47,8 +47,8 @@ def get_wagtail_userbar(self, page): if not request: return None - is_preview = getattr(request, "is_preview", False) - if is_preview: + in_preview_panel = getattr(request, "in_preview_panel", False) + if in_preview_panel: return None if not hasattr(request, "user"): diff --git a/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py b/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py index 985b297a6..cec2455b8 100644 --- a/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py +++ b/{{cookiecutter.project_name}}/src/main/pages/base_serializer.py @@ -47,8 +47,8 @@ def get_wagtail_userbar(self, page): if not request: return None - is_preview = getattr(request, "is_preview", False) - if is_preview: + in_preview_panel = getattr(request, "in_preview_panel", False) + if in_preview_panel: return None if not hasattr(request, "user"): From 3c5abe6babc0a749567c884f77ce0e8074378f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Sat, 19 Aug 2023 06:50:43 +0200 Subject: [PATCH 5/8] Drop non running get_preview_url override --- CHANGELOG.md | 1 + Company-Project/src/main/pages/base.py | 16 ---------------- .../src/main/pages/base.py | 16 ---------------- 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f82c9fd4..90746f3a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix bug preventing request.is_preview from being set - Hide wagtail userbar when in preview panel - Make sure in_preview_panel is set +- Drop non running get_preview_url override from base page (@marteinn) ### Removed diff --git a/Company-Project/src/main/pages/base.py b/Company-Project/src/main/pages/base.py index 239b81425..ea1b46dd1 100644 --- a/Company-Project/src/main/pages/base.py +++ b/Company-Project/src/main/pages/base.py @@ -68,19 +68,3 @@ def to_dict( def get_serializer_class(self) -> Type[Serializer]: cls: Type[Serializer] = import_string(self.serializer_class) return cls - - def get_preview_url(self, token): - """ - Override wagtail_headless_preview/get_preview_url and append hostname - """ - import urllib - - preview_url = super().get_preview_url(token) - preview_url = ( - preview_url - + "&" - + urllib.parse.urlencode( - {"host": f"{self.get_site().hostname}:{self.get_site().port}"} - ) - ) - return preview_url diff --git a/{{cookiecutter.project_name}}/src/main/pages/base.py b/{{cookiecutter.project_name}}/src/main/pages/base.py index 239b81425..ea1b46dd1 100644 --- a/{{cookiecutter.project_name}}/src/main/pages/base.py +++ b/{{cookiecutter.project_name}}/src/main/pages/base.py @@ -68,19 +68,3 @@ def to_dict( def get_serializer_class(self) -> Type[Serializer]: cls: Type[Serializer] = import_string(self.serializer_class) return cls - - def get_preview_url(self, token): - """ - Override wagtail_headless_preview/get_preview_url and append hostname - """ - import urllib - - preview_url = super().get_preview_url(token) - preview_url = ( - preview_url - + "&" - + urllib.parse.urlencode( - {"host": f"{self.get_site().hostname}:{self.get_site().port}"} - ) - ) - return preview_url From c6387b08cf0ad4543f4a87e154a6375fb5cfeb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Sat, 19 Aug 2023 06:51:50 +0200 Subject: [PATCH 6/8] Add changelog credits --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90746f3a1..148c1a4c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed ### Fixed -- Fix bug preventing request.is_preview from being set -- Hide wagtail userbar when in preview panel -- Make sure in_preview_panel is set +- Fix bug preventing request.is_preview from being set (@marteinn) +- Hide wagtail userbar when in preview panel (@marteinn) +- Make sure in_preview_panel is set (@marteinn) - Drop non running get_preview_url override from base page (@marteinn) ### Removed From 9dc63b191fc0ea558eac94a43a184bea4e73b7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Tue, 22 Aug 2023 19:56:39 +0200 Subject: [PATCH 7/8] Remove deprecated wagtail.contrib.modeladmin from INSTALLED_APPS --- CHANGELOG.md | 1 + Company-Project/src/pipit/settings/base.py | 1 - {{cookiecutter.project_name}}/src/pipit/settings/base.py | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 148c1a4c1..ec435c236 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Hide wagtail userbar when in preview panel (@marteinn) - Make sure in_preview_panel is set (@marteinn) - Drop non running get_preview_url override from base page (@marteinn) +- Remove deprecated wagtail.contrib.modeladmin from INSTALLED_APPS (@marteinn) ### Removed diff --git a/Company-Project/src/pipit/settings/base.py b/Company-Project/src/pipit/settings/base.py index 82220bba1..e5a02e6f9 100644 --- a/Company-Project/src/pipit/settings/base.py +++ b/Company-Project/src/pipit/settings/base.py @@ -44,7 +44,6 @@ "wagtail", "wagtail.contrib.forms", "wagtail.contrib.redirects", - "wagtail.contrib.modeladmin", "wagtail.contrib.routable_page", "wagtail.contrib.settings", "modelcluster", diff --git a/{{cookiecutter.project_name}}/src/pipit/settings/base.py b/{{cookiecutter.project_name}}/src/pipit/settings/base.py index 3d1eb05e8..f09d86d79 100644 --- a/{{cookiecutter.project_name}}/src/pipit/settings/base.py +++ b/{{cookiecutter.project_name}}/src/pipit/settings/base.py @@ -44,7 +44,6 @@ "wagtail", "wagtail.contrib.forms", "wagtail.contrib.redirects", - "wagtail.contrib.modeladmin", "wagtail.contrib.routable_page", "wagtail.contrib.settings", "modelcluster", From 0397f3c399420bfa60849af8c11ef30c880b9e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sandstr=C3=B6m?= Date: Tue, 22 Aug 2023 19:58:41 +0200 Subject: [PATCH 8/8] Bump changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec435c236..41cee87e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added ### Changed +### Fixed +### Removed + +## [8.12.3] - 2023-08-22 + ### Fixed - Fix bug preventing request.is_preview from being set (@marteinn) - Hide wagtail userbar when in preview panel (@marteinn) - Make sure in_preview_panel is set (@marteinn) - Drop non running get_preview_url override from base page (@marteinn) -- Remove deprecated wagtail.contrib.modeladmin from INSTALLED_APPS (@marteinn) ### Removed +- Remove deprecated wagtail.contrib.modeladmin app from INSTALLED_APPS (@marteinn) ## [8.12.2] - 2023-08-16