Skip to content

Commit

Permalink
Fix locale selector link in page explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage authored and thibaudcolas committed Jul 19, 2022
1 parent de53c7b commit efaad25
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
21 changes: 21 additions & 0 deletions wagtail/admin/tests/pages/test_explorer_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,14 +735,35 @@ def test_locale_selector(self):
response = self.client.get(
reverse("wagtailadmin_explore", args=[self.events_page.id])
)
html = response.content.decode()

self.assertContains(response, 'id="status-sidebar-english"')
self.assertContains(response, "Switch locales")

add_translation_url = reverse(
"wagtailadmin_explore", args=[self.translated_events_page.id]
)
self.assertTagInHTML(
f'<a href="{add_translation_url}" lang="fr">French</a>',
html,
allow_extra_attrs=True,
)

@override_settings(WAGTAIL_I18N_ENABLED=False)
def test_locale_selector_not_present_when_i18n_disabled(self):
response = self.client.get(
reverse("wagtailadmin_explore", args=[self.events_page.id])
)
html = response.content.decode()

self.assertNotContains(response, "Switch locales")

add_translation_url = reverse(
"wagtailadmin_explore", args=[self.translated_events_page.id]
)
self.assertTagInHTML(
f'<a href="{add_translation_url}" lang="fr">French</a>',
html,
allow_extra_attrs=True,
count=0,
)
18 changes: 13 additions & 5 deletions wagtail/admin/ui/side_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class BaseStatusSidePanel(BaseSidePanel):
toggle_aria_label = gettext_lazy("Toggle status")
toggle_icon_name = "info-circle"

def __init__(self, *args, in_explorer=False, **kwargs):
super().__init__(*args, **kwargs)
self.in_explorer = in_explorer

def get_status_templates(self, context):
templates = []

Expand Down Expand Up @@ -86,15 +90,17 @@ def get_context_data(self, parent_context):
)

if getattr(settings, "WAGTAIL_I18N_ENABLED", False):
url_name = "wagtailadmin_pages:edit"
if self.in_explorer:
url_name = "wagtailadmin_explore"

context.update(
{
"locale": page.locale,
"translations": [
{
"locale": translation.locale,
"url": reverse(
"wagtailadmin_pages:edit", args=[translation.id]
),
"url": reverse(url_name, args=[translation.id]),
}
for translation in page.get_translations()
.only("id", "locale", "depth")
Expand Down Expand Up @@ -178,11 +184,13 @@ def media(self):


class PageSidePanels(BaseSidePanels):
def __init__(self, request, page, *, preview_enabled, comments_enabled):
def __init__(
self, request, page, *, preview_enabled, comments_enabled, in_explorer=False
):
super().__init__(request, page)

self.side_panels = [
PageStatusSidePanel(page, self.request),
PageStatusSidePanel(page, self.request, in_explorer=in_explorer),
]

if preview_enabled and page.preview_modes:
Expand Down
1 change: 1 addition & 0 deletions wagtail/admin/views/pages/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def index(request, parent_page_id=None):
side_panels = PageSidePanels(
request,
parent_page.specific,
in_explorer=True,
preview_enabled=False,
comments_enabled=False,
)
Expand Down

0 comments on commit efaad25

Please sign in to comment.