Skip to content

Commit

Permalink
fix: Modify language menu for pages only if it is present (#333)
Browse files Browse the repository at this point in the history
* Compile messages

* Add locale directory to manifest

* fix:  Pages do not need to have. a language menu. Only try modifying if it is there.

* Add test

* Update tests/test_toolbars.py

Co-authored-by: Mark Walker <[email protected]>

---------

Co-authored-by: Mark Walker <[email protected]>
  • Loading branch information
fsbraun and marksweb authored May 23, 2023
1 parent 91eafe1 commit 3df6225
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
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
24 changes: 24 additions & 0 deletions tests/test_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,27 @@ 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):
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)

0 comments on commit 3df6225

Please sign in to comment.