diff --git a/src/core/models/pages.py b/src/core/models/pages.py index b8b3164ab8a665baf2ba8b15c74c466600179f24..6b5a1bd33bbdbde847bd1d8b31952b91c4e7269c 100644 --- a/src/core/models/pages.py +++ b/src/core/models/pages.py @@ -196,14 +196,14 @@ class StaticPageManager(models.Manager): def get_editable_page(self, user: PlatformUser, conference: Conference, language: str, slug: str, check=False) -> tuple['StaticPage | None', bool]: """ - Request to edit the Static Page with slug `slug` in the context of `user` and `conference` and in the language `langguage`. + Request to edit the Static Page with slug `slug` in the context of `user` and `conference` and in the language `language`. Returns a tuple `(static_page, exists)` with `static_page` the `StaticPage` instance (or `None`) and `exists` a boolean iff the `StaticPage` already exists in the database and the user has sufficient permission to create it. `static_page` will be `None` iff the user is not allowed to edit this Page (even if it does not exist). Otherwise, it will be a `StaticPage` instance for the Page. - If the Page does not yet exist in the database, the returned `StaticPage` is not stored in the database (`save()` needs to be called by the callee). + If the Page does not yet exist in the database, the returned `StaticPage` is not stored in the database (`save()` needs to be called by the caller). In this case, `exists` will be `False`. """ diff --git a/src/plainui/tests/test_views.py b/src/plainui/tests/test_views.py index d04f35c6685bd0e845aad02298de82cb62c105c8..8873c92911fcc18d7725f5cc2dfe6d78effc86e7 100644 --- a/src/plainui/tests/test_views.py +++ b/src/plainui/tests/test_views.py @@ -667,6 +667,7 @@ class ViewsTest(ViewsTestBase): self.assertEqual(resp.context_data['page'], sp) self.assertEqual(resp.context_data['page_slug'], sp.slug) self.assertEqual(resp.context_data['writeable'], False) + self.assertEqual(resp.context_data['lock_id'], '') self.assertEqual(resp.context_data['revision'], None) self.assertIsInstance(resp.context_data['form'], StaticPageBodyForm) self.assertEqual(resp.context_data['form']['title'].value(), r2.title) @@ -701,6 +702,7 @@ class ViewsTest(ViewsTestBase): self.assertEqual(resp.context_data['page'], sp) self.assertEqual(resp.context_data['page_slug'], sp.slug) self.assertEqual(resp.context_data['writeable'], False) + self.assertEqual(resp.context_data['lock_id'], '') self.assertEqual(resp.context_data['revision'], None) self.assertIsInstance(resp.context_data['form'], StaticPageBodyForm) self.assertEqual(resp.context_data['form']['title'].value(), r2.title) @@ -757,6 +759,7 @@ class ViewsTest(ViewsTestBase): self.assertEqual(resp.context_data['page_slug'], 'test-doesnotexist') self.assertEqual(resp.context_data['writeable'], True) self.assertEqual(resp.context_data['revision'], None) + self.assertEqual(resp.context_data['lock_id'], '') # no lock self.assertIsInstance(resp.context_data['form'], StaticPageBodyForm) self.assertEqual(resp.context_data['form']['title'].value(), 'test-doesnotexist') self.assertEqual(resp.context_data['form']['body'].value(), '') diff --git a/src/plainui/views/static_pages.py b/src/plainui/views/static_pages.py index 924a27684fd016d4f34d19c0d3edeb4bf52fcf09..a4da70392cb44fa9a6c5d59b65eeb857c53cb9d1 100644 --- a/src/plainui/views/static_pages.py +++ b/src/plainui/views/static_pages.py @@ -152,7 +152,7 @@ class StaticPageEditView(ConferenceRequiredMixin, TemplateView): return redirect(reverse('plainui:static_page', kwargs={'page_slug': page_slug})) lock = '' - if page_exists: + if page_exists and writeable: lock, created = Lock.objects.select_for_update().get_or_create( content_type=ContentType.objects.get_for_model(StaticPage), object_id=static_page.pk,