mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-05 14:04:46 +00:00
Unicode support for slug as of Django 1.9
This commit is contained in:
parent
33441f1ff7
commit
b1f194a637
7 changed files with 48 additions and 8 deletions
|
|
@ -4,6 +4,7 @@ Changelog
|
|||
1.6 (xx.xx.xxxx) - IN DEVELOPMENT
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
* Page slugs now allow unicode on Django >= 1.9 (Behzad Nategh)
|
||||
* Image upload form in image chooser now performs client side validation so that the selected file is not lost in the submission (Jack Paine)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ Contributors
|
|||
* Bojan Mihelac
|
||||
* Robert Moggach
|
||||
* Stephen Rice
|
||||
* Behzad Nategh
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ What's new
|
|||
Minor features
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
* Page slugs now allow unicode on Django >= 1.9 (Behzad Nategh)
|
||||
* Image upload form in image chooser now performs client side validation so that the selected file is not lost in the submission (Jack Paine)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -260,9 +260,9 @@ function InlinePanel(opts) {
|
|||
|
||||
function cleanForSlug(val, useURLify) {
|
||||
if (URLify != undefined && useURLify !== false) { // Check to be sure that URLify function exists, and that we want to use it.
|
||||
return URLify(val);
|
||||
return URLify(val, 255, true);
|
||||
} else { // If not just do the "replace"
|
||||
return val.replace(/\s/g, '-').replace(/[^A-Za-z0-9\-\_]/g, '').toLowerCase();
|
||||
return val.replace(/\s/g, '-').replace(/[&\/\\#,+()$~%.'":`@\^!*?<>{}\_]/g, '').toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
<script src="{% static 'wagtailadmin/js/modal-workflow.js' %}"></script>
|
||||
<script src="{% static 'wagtailadmin/js/page-editor.js' %}"></script>
|
||||
<script src="{% static 'wagtailadmin/js/page-chooser.js' %}"></script>
|
||||
<script src="{% static 'admin/js/vendor/xregexp/xregexp.min.js' %}"></script>
|
||||
<script src="{% static 'admin/js/urlify.js' %}"></script>
|
||||
<script src="{% static 'wagtailadmin/js/privacy-switch.js' %}"></script>
|
||||
<script src="{% static 'wagtailadmin/js/vendor/bootstrap-tooltip.js' %}"></script>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.4 on 2016-04-27 22:39
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
from django import VERSION as DJANGO_VERSION
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wagtailcore', '0028_merge'),
|
||||
]
|
||||
|
||||
operations = []
|
||||
if DJANGO_VERSION >= (1, 9):
|
||||
operations += [
|
||||
migrations.AlterField(
|
||||
model_name='page',
|
||||
name='slug',
|
||||
field=models.SlugField(allow_unicode=True, help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255, verbose_name='slug'),
|
||||
),
|
||||
]
|
||||
|
|
@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
|
|||
import json
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from django import VERSION as DJANGO_VERSION
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
|
|
@ -296,11 +297,20 @@ class Page(six.with_metaclass(PageBase, MP_Node, index.Indexed, ClusterableModel
|
|||
max_length=255,
|
||||
help_text=_("The page title as you'd like it to be seen by the public")
|
||||
)
|
||||
slug = models.SlugField(
|
||||
verbose_name=_('slug'),
|
||||
max_length=255,
|
||||
help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/")
|
||||
)
|
||||
# use django 1.9+ SlugField with unicode support
|
||||
if DJANGO_VERSION >= (1, 9):
|
||||
slug = models.SlugField(
|
||||
verbose_name=_('slug'),
|
||||
allow_unicode=True,
|
||||
max_length=255,
|
||||
help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/")
|
||||
)
|
||||
else:
|
||||
slug = models.SlugField(
|
||||
verbose_name=_('slug'),
|
||||
max_length=255,
|
||||
help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/")
|
||||
)
|
||||
content_type = models.ForeignKey(
|
||||
'contenttypes.ContentType',
|
||||
verbose_name=_('content type'),
|
||||
|
|
@ -444,7 +454,10 @@ class Page(six.with_metaclass(PageBase, MP_Node, index.Indexed, ClusterableModel
|
|||
|
||||
if not self.slug:
|
||||
# Try to auto-populate slug from title
|
||||
base_slug = slugify(self.title)
|
||||
if DJANGO_VERSION >= (1, 9):
|
||||
base_slug = slugify(self.title, allow_unicode=True)
|
||||
else:
|
||||
base_slug = slugify(self.title)
|
||||
|
||||
# only proceed if we get a non-empty base slug back from slugify
|
||||
if base_slug:
|
||||
|
|
|
|||
Loading…
Reference in a new issue