8000 fix: Consistent toolbar mode by fsbraun · Pull Request #8011 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Consistent toolbar mode #8011

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

Merged
merged 4 commits into from
Sep 27, 2024
Merged
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
46 changes: 46 additions & 0 deletions cms/tests/test_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ def test_hide_toolbar_disabled(self):
self.assertTrue(request.session.get('cms_toolbar_disabled'))
toolbar = CMSToolbar(request)
self.assertFalse(toolbar.edit_mode_active)
self.assertFalse(toolbar.structure_mode_active)
self.assertFalse(toolbar.preview_mode_active)

def test_show_disabled_toolbar_with_edit(self):
page = create_page("toolbar-page", "nav_playground.html", "en")
Expand Down Expand Up @@ -1004,6 +1006,50 @@ def test_toolbar_logout_redirect(self):
self.assertEqual(admin_menu.find_first(AjaxItem, name=menu_name).item.on_success, '/')


class ToolbarModeTests(ToolbarTestBase):
def setUp(self):
super().setUp()
self.page = create_page("home", "nav_playground.html", "en")
self.page_content = self.get_pagecontent_obj(self.page)

def tearDown(self):
self.page.delete()
super().tearDown()

def test_edit_mode(self):
"""Only edit mode is active"""
page_edit_url = get_object_edit_url(self.page_content)
with self.login_user_context(self.get_superuser()):
response = self.client.get(page_edit_url)
toolbar = response.context['request'].toolbar

self.assertTrue(toolbar.edit_mode_active)
self.assertFalse(toolbar.structure_mode_active)
self.assertFalse(toolbar.preview_mode_active)

def test_preview_mode(self):
"""Only preview mode is active"""
page_preview_url = get_object_preview_url(self.page_content)
with self.login_user_context(self.get_superuser()):
response = self.client.get(page_preview_url)
toolbar = response.context['request'].toolbar

self.assertFalse(toolbar.edit_mode_active)
self.assertFalse(toolbar.structure_mode_active)
self.assertTrue(toolbar.preview_mode_active)

def test_structure_mode(self):
"""Structure AND edit mode is active"""
page_structure_url = get_object_structure_url(self.page_content)
with self.login_user_context(self.get_superuser()):
response = self.client.get(page_structure_url)
toolbar = response.context['request'].toolbar

self.assertTrue(toolbar.edit_mode_active)
self.assertTrue(toolbar.structure_mode_active)
self.assertFalse(toolbar.preview_mode_active)


@override_settings(ROOT_URLCONF='cms.test_utils.project.placeholderapp_urls')
class EditModelTemplateTagTest(ToolbarTestBase):
edit_fields_rx = "(\\?|&)edit_fields=%s"
Expand Down
9 changes: 0 additions & 9 deletions cms/toolbar/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,6 @@ def object_is_editable(self, obj=None):
return True
return False

@cached_property
def edit_mode_active(self):
"""``True`` if editing mode is active。"""
# Cannot be cached since it changes depending on the object.
if self.structure_mode_active:
return self.object_is_editable()
return super().edit_mode_active


# Internal API

def _add_item(self, item, position=None):
Expand Down
Loading
0