瀏覽代碼

allows unicode string in page copy form (#5991)

* resolve #5990
François Poulain 4 年之前
父節點
當前提交
55e65be079
共有 5 個文件被更改,包括 27 次插入3 次删除
  1. 1 0
      CHANGELOG.txt
  2. 1 0
      CONTRIBUTORS.rst
  3. 1 0
      docs/releases/2.10.rst
  4. 3 1
      wagtail/admin/forms/pages.py
  5. 21 2
      wagtail/admin/tests/pages/test_copy_page.py

+ 1 - 0
CHANGELOG.txt

@@ -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

+ 1 - 0
CONTRIBUTORS.rst

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

+ 1 - 0
docs/releases/2.10.rst

@@ -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

+ 3 - 1
wagtail/admin/forms/pages.py

@@ -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(),

+ 21 - 2
wagtail/admin/tests/pages/test_copy_page.py

@@ -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