allows unicode string in page copy form (#5991)

* resolve #5990
pull/5997/head
François Poulain 2020-04-27 19:21:31 +02:00 zatwierdzone przez Matt Westcott
rodzic f4d47a88d0
commit 55e65be079
5 zmienionych plików z 27 dodań i 3 usunięć

Wyświetl plik

@ -17,6 +17,7 @@ Changelog
* Fix: `AbstractEmailForm` saved submission fields are now aligned with the email content fields, `form.cleaned_data` will be used instead of `form.fields` (Haydn Greatnews)
* Fix: Removed ARIA `role="table"` from TableBlock output (Thibaud Colas)
* Fix: Set Cache-Control header to prevent page preview responses from being cached (Tomas Walch)
* Fix: Accept unicode characters in slugs on the "copy page" form (François Poulain)
2.9 (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -451,6 +451,7 @@ Contributors
* Ascani Carlo
* Chris Ranjana
* Tomas Walch
* François Poulain
Translators
===========

Wyświetl plik

@ -31,6 +31,7 @@ Bug fixes
* ``AbstractEmailForm`` saved submission fields are now aligned with the email content fields, ``form.cleaned_data`` will be used instead of ``form.fields`` (Haydn Greatnews)
* Removed ARIA ``role="table"`` from TableBlock output (Thibaud Colas)
* Set Cache-Control header to prevent page preview responses from being cached (Tomas Walch)
* Accept unicode characters in slugs on the "copy page" form (François Poulain)
Upgrade considerations

Wyświetl plik

@ -1,4 +1,5 @@
from django import forms
from django.conf import settings
from django.utils import timezone
from django.utils.translation import gettext as _
from django.utils.translation import ngettext
@ -18,7 +19,8 @@ class CopyForm(forms.Form):
can_publish = kwargs.pop('can_publish')
super().__init__(*args, **kwargs)
self.fields['new_title'] = forms.CharField(initial=self.page.title, label=_("New title"))
self.fields['new_slug'] = forms.SlugField(initial=self.page.slug, label=_("New slug"))
allow_unicode = getattr(settings, 'WAGTAIL_ALLOW_UNICODE_SLUGS', True)
self.fields['new_slug'] = forms.SlugField(initial=self.page.slug, label=_("New slug"), allow_unicode=allow_unicode)
self.fields['new_parent_page'] = forms.ModelChoiceField(
initial=self.page.get_parent(),
queryset=Page.objects.all(),

Wyświetl plik

@ -310,13 +310,32 @@ class TestPageCopy(TestCase, WagtailTestUtils):
# Check that a form error was raised
if DJANGO_VERSION >= (3, 0):
self.assertFormError(
response, 'form', 'new_slug', "Enter a valid “slug” consisting of letters, numbers, underscores or hyphens."
response, 'form', 'new_slug', "Enter a valid “slug” consisting of Unicode letters, numbers, underscores, or hyphens."
)
else:
self.assertFormError(
response, 'form', 'new_slug', "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."
response, 'form', 'new_slug', "Enter a valid 'slug' consisting of Unicode letters, numbers, underscores, or hyphens."
)
def test_page_copy_post_valid_unicode_slug(self):
post_data = {
'new_title': "Hello wɜːld",
'new_slug': 'hello-wɜːld',
'new_parent_page': str(self.test_page.id),
'copy_subpages': False,
}
response = self.client.post(reverse('wagtailadmin_pages:copy', args=(self.test_page.id, )), post_data)
# Check response
self.assertRedirects(response, reverse('wagtailadmin_explore', args=(self.test_page.id, )))
# Get copy
page_copy = self.test_page.get_children().filter(slug=post_data['new_slug']).first()
# Check that the copy exists with the good slug
self.assertNotEqual(page_copy, None)
self.assertEqual(page_copy.slug, post_data['new_slug'])
def test_page_copy_no_publish_permission(self):
# Turn user into an editor who can add pages but not publish them
self.user.is_superuser = False