Skip to content

Conversation

@va-lang
Copy link

@va-lang va-lang commented Oct 31, 2025

Description

django CMS versioning "takes over" the language menu for pages.
However, unlike the behavior of the django CMS core, the language menu was being displayed even when only one language was configured.

Fixes DjangoCMS-#469

Related resources

cms_toolbars.py#L438-L46

  • #...
  • #...

Checklist

  • I have opened this pull request against master
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined #workgroup-pr-review on
    Slack to find a “pr review buddy” who is going to review my pull request.

Bug Fixes:

Fixes an issue where the language menu was displayed even when only one language was configured.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 31, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduce an early exit in the language menu logic to skip rendering when a page only has one language and update tests to configure languages explicitly and validate this behavior.

Flow diagram for language menu rendering logic

flowchart TD
    A["User requests page"] --> B["Get configured languages for site"]
    B --> C["Get languages for current page"]
    C --> D{"Are there at least 2 site languages?"}
    D -- No --> E["Do not show language menu"]
    D -- Yes --> F{"Are there at least 2 page languages?"}
    F -- No --> E
    F -- Yes --> G["Show language menu"]
Loading

File-Level Changes

Change Details Files
Skip rendering the language menu for pages configured with a single language
  • Fetch page-specific languages via get_languages()
  • Add an early return when page_languages length is less than 2
  • Retain existing early return for site languages under two
djangocms_versioning/cms_toolbars.py
Adjust language menu label to plural form
  • Change menu title argument from _('Language') to _('Languages')
djangocms_versioning/cms_toolbars.py
Enhance tests to simulate single-language pages and assert menu absence
  • Set content__language explicitly and invoke page.update_languages(['en'])
  • Retrieve toolbar from the updated page object
  • Refine assertion with a descriptive message when menu should be None
tests/test_toolbars.py

Assessment against linked issues

Issue Objective Addressed Explanation
#469 Hide the language menu when only one language is configured for the site or the current page.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Nov 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.67%. Comparing base (a132204) to head (b2bb172).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #491      +/-   ##
==========================================
+ Coverage   90.55%   93.67%   +3.12%     
==========================================
  Files          72       76       +4     
  Lines        2732     2689      -43     
  Branches      322        0     -322     
==========================================
+ Hits         2474     2519      +45     
+ Misses        182      170      -12     
+ Partials       76        0      -76     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@marbru marbru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on your first PR! Left a couple comments from my point of view, perhaps @fsbraun has more.

@fsbraun
Copy link
Member

fsbraun commented Nov 4, 2025

@va-lang I have now installed the patch to check the UI. A new thought came to my mind and I would love to get your opinion on that:

  • I still believe a menu with no real options to do anything does not make sense. If only one language is installed, the language menu is already hidden, so now we're looking at what happens if you have only one language for the page your looking it.
  • Besides hiding it also in this case, the user could want to add a language. That's currently only possible from the page tree or if you edit the current language. This seems inconsistent. IMHO you could also add a new language from the preview page.

What do you think of this alternative: Instead of hiding the menu, we also add the "add" and "remove" submenus in preview mode (inside override_language_menu).

The menu would be there and look something like this:

Language
--------
+ English
  ------------
  Add language
  + French
  | German
  Remove language
  + English (disabled)

Now there are things, the user can do, e.g. add a French version of the page.

Let me know what you think!

@va-lang
Copy link
Author

va-lang commented Nov 4, 2025

@fsbraun That’s a great point, I agree that showing an empty menu when there’s only one language doesn’t add much value, and extending it to include “Add” and “Remove” options in preview mode could make the behavior more consistent and user-friendly.
I can explore adding the “Add/Remove language” options inside override_language_menu so users can create or remove translations directly from the preview. That way, the menu remains visible and functional, even when there’s only one language configured.

Would update the PR

class VersioningToolbarTestCase(CMSTestCase):
def _get_publish_url(self, version, versionable=PollsCMSConfig.versioning[0]):
"""Helper method to return the expected publish url
"""

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'cms_toolbars' is not used.
@fsbraun
Copy link
Member

fsbraun commented Nov 6, 2025

@va-lang Thanks, well done!

I am not sure of the overall logic, though. Here's what I would expect:

  • can_change should be page_permissions.user_can_change_page(...), i.e. not be dependent on the edit mode
  • add and remove are only possible if the user has change permissions (i.e., can_change is set)
  • copy is only possible, if also edit_mode_active is set

Finally, if the user cannot change the page, and only one language is available, shall we hide the language menu as anticipated in the beginning?


language_menu = request.toolbar.get_menu(LANGUAGE_MENU_IDENTIFIER)
self.assertIsNone(language_menu)
self.assertIsNone(language_menu, "Language menu should not be created if the page has only one language.")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up: we forgot to remove the modifications done to this test case. Just copypaste the code from the master branch to make sure it stays the same: https://github.com/django-cms/djangocms-versioning/blob/master/tests/test_toolbars.py#L499

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Language menu is showing despite only one language configured

3 participants