kopia lustrzana https://github.com/wagtail/wagtail
Add missing locale context value in page create and edit views
The value was removed in #10864 as we moved the locale code into the side panels, but the view template still has references to the locale for the hidden input in create.html and for the ACTIVE_CONTENT_LOCALEpull/11017/head
rodzic
29d73a3b68
commit
9bf7d88869
|
@ -1743,6 +1743,7 @@ class TestLocaleSelectorOnRootPage(WagtailTestUtils, TestCase):
|
|||
|
||||
self.assertContains(response, 'id="status-sidebar-english"')
|
||||
|
||||
# Should show a link to switch to another locale
|
||||
add_translation_url = (
|
||||
reverse(
|
||||
"wagtailadmin_pages:add",
|
||||
|
@ -1752,6 +1753,50 @@ class TestLocaleSelectorOnRootPage(WagtailTestUtils, TestCase):
|
|||
)
|
||||
self.assertContains(response, f'href="{add_translation_url}"')
|
||||
|
||||
# Should not show a link to switch to the current locale
|
||||
self_translation_url = (
|
||||
reverse(
|
||||
"wagtailadmin_pages:add",
|
||||
args=["demosite", "homepage", self.root_page.id],
|
||||
)
|
||||
+ "?locale=en"
|
||||
)
|
||||
self.assertNotContains(response, f'href="{self_translation_url}"')
|
||||
|
||||
def test_locale_selector_selected(self):
|
||||
response = self.client.get(
|
||||
reverse(
|
||||
"wagtailadmin_pages:add",
|
||||
args=["demosite", "homepage", self.root_page.id],
|
||||
)
|
||||
+ "?locale=fr"
|
||||
)
|
||||
|
||||
self.assertContains(response, 'id="status-sidebar-french"')
|
||||
|
||||
# Should render the locale input with the currently selected locale
|
||||
self.assertContains(response, '<input type="hidden" name="locale" value="fr">')
|
||||
|
||||
# Should show a link to switch to another locale
|
||||
add_translation_url = (
|
||||
reverse(
|
||||
"wagtailadmin_pages:add",
|
||||
args=["demosite", "homepage", self.root_page.id],
|
||||
)
|
||||
+ "?locale=en"
|
||||
)
|
||||
self.assertContains(response, f'href="{add_translation_url}"')
|
||||
|
||||
# Should not show a link to switch to the current locale
|
||||
self_translation_url = (
|
||||
reverse(
|
||||
"wagtailadmin_pages:add",
|
||||
args=["demosite", "homepage", self.root_page.id],
|
||||
)
|
||||
+ "?locale=fr"
|
||||
)
|
||||
self.assertNotContains(response, f'href="{self_translation_url}"')
|
||||
|
||||
@override_settings(WAGTAIL_I18N_ENABLED=False)
|
||||
def test_locale_selector_not_present_when_i18n_disabled(self):
|
||||
response = self.client.get(
|
||||
|
|
|
@ -390,6 +390,7 @@ class CreateView(TemplateResponseMixin, ContextMixin, HookResponseMixin, View):
|
|||
"form": self.form,
|
||||
"next": self.next_url,
|
||||
"has_unsaved_changes": self.has_unsaved_changes,
|
||||
"locale": self.locale,
|
||||
"media": media,
|
||||
}
|
||||
)
|
||||
|
@ -413,7 +414,8 @@ class CreateView(TemplateResponseMixin, ContextMixin, HookResponseMixin, View):
|
|||
+ "?"
|
||||
+ urlencode({"locale": locale.language_code}),
|
||||
}
|
||||
for locale in Locale.objects.all()
|
||||
# Do not show the switcher for the current locale
|
||||
for locale in Locale.objects.exclude(pk=self.locale.pk)
|
||||
]
|
||||
|
||||
else:
|
||||
|
|
|
@ -939,6 +939,7 @@ class EditView(TemplateResponseMixin, ContextMixin, HookResponseMixin, View):
|
|||
and user_perms.can_lock(),
|
||||
"user_can_unlock": isinstance(self.lock, BasicLock)
|
||||
and user_perms.can_unlock(),
|
||||
"locale": self.locale,
|
||||
"media": media,
|
||||
}
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue