Skip to content
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

fix: Modify language menu for pages only if it is present #333

Merged
merged 5 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog

Unreleased
==========
* fix: Only try modifying page language menu if it is present
* fix: Added ``related_name`` attribute to the ``content_type`` foreign key of the ``Version`` model.
* fix: burger menu adjusts to the design of django cms core dropdown
* fix: bug that showed an archived version as unpublished in some cases in the state indicator
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ include LICENSE.txt
include README.rst
recursive-include djangocms_versioning/static *
recursive-include djangocms_versioning/templates *
recursive-include djangocms_versioning/locale *
recursive-exclude * *.pyc
7 changes: 3 additions & 4 deletions djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,9 @@ def override_language_menu(self):
Override the default language menu for pages that are versioned.
The default language menu is too generic so for pages we need to replace it.
"""
# Only override the menu if a page can be found
if settings.USE_I18N and self.page:
language_menu = self.toolbar.get_menu(LANGUAGE_MENU_IDENTIFIER, _("Language"))

# Only override the menu if it exists and a page can be found
language_menu = self.toolbar.get_menu(LANGUAGE_MENU_IDENTIFIER, _("Language"))
if settings.USE_I18N and language_menu and self.page:
# remove_item uses `items` attribute so we have to copy object
for _item in copy(language_menu.items):
language_menu.remove_item(item=_item)
Expand Down
Binary file modified djangocms_versioning/locale/de/LC_MESSAGES/django.mo
Binary file not shown.
Binary file modified djangocms_versioning/locale/nl/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion djangocms_versioning/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ msgstr "Actie niet geldig. De laatste versie is gesloten door {user}"
#: models.py:33
#, python-brace-format
msgid "Action Denied. The draft version is locked by {user}"
msgstr "Actie niet geldig. De concept versie is gesloten door "
msgstr "Actie niet geldig. De concept versie is gesloten door {user}"

#: models.py:88
msgid "Created"
Expand Down
23 changes: 23 additions & 0 deletions tests/test_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,26 @@ def test_change_language_menu_page_toolbar_language_selector_version_link(self):
self.assertEqual(en_item.url, en_preview_url)
self.assertEqual(de_item.url, de_preview_url)
self.assertEqual(it_item.url, it_preview_url)
def test_page_toolbar_wo_language_menu(self):
fsbraun marked this conversation as resolved.
Show resolved Hide resolved
from django.utils.translation import gettext as _

pagecontent = PageContentWithVersionFactory(language="en")
page = pagecontent.page
# Get request
request = self.get_page_request(
page=page,
path=get_object_edit_url(pagecontent),
user=self.get_superuser(),
)
# Remove language menu from request's toolbar
del request.toolbar.menus[LANGUAGE_MENU_IDENTIFIER]

# find VersioningPageToolbar
for cls, toolbar in request.toolbar.toolbars.items():
if cls == "djangocms_versioning.cms_toolbars.VersioningPageToolbar":
# and call override_language_menu
toolbar.override_language_menu()
break

language_menu = request.toolbar.get_menu(LANGUAGE_MENU_IDENTIFIER, _("Language"))
self.assertIsNone(language_menu)