Skip to content

Commit

Permalink
Replace slugify with unicode-aware filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Vetter committed Dec 20, 2013
1 parent 325a5aa commit d3e6356
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fancypages/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.utils import timezone
from django.contrib.contenttypes import generic
from django.core.exceptions import ValidationError
from django.template.defaultfilters import slugify
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import get_language, ugettext_lazy as _
Expand All @@ -13,6 +12,7 @@
from model_utils.managers import InheritanceManager

from . import mixins
from .utils import unicode_slugify as slugify
from .managers import PageManager, ContainerManager
from .utils import get_container_names_from_template

Expand Down
2 changes: 1 addition & 1 deletion fancypages/dashboard/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django import forms
from django.db.models import get_model
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _

from ..utils import unicode_slugify as slugify
from ..utils import get_page_model, get_node_model

PageNode = get_node_model()
Expand Down
2 changes: 1 addition & 1 deletion fancypages/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from django.conf import settings
from django.utils import simplejson as json
from django.utils.encoding import force_unicode
from django.template.defaultfilters import slugify
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _

from .utils import get_page_model
from .defaults import FP_HOMEPAGE_NAME
from .utils import unicode_slugify as slugify


class FancyPageMixin(object):
Expand Down
5 changes: 3 additions & 2 deletions fancypages/templates/fancypages/dashboard/block_select.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load fp_filters %}
{% load staticfiles %}
{% load url from future %}

Expand All @@ -15,14 +16,14 @@ <h3>Add content</h3>
<ul class="fp-nav-tabs">
{% for group in grouped_blocks %}
<li {% if forloop.first %}class="active"{% endif %}>
<a href="#{{ group|slugify }}" data-toggle="tab">{{ group }}</a>
<a href="#{{ group|fp_slugify }}" data-toggle="tab">{{ group }}</a>
</li>
{% endfor %}
</ul>

<div class="fp-tab-content">
{% for group,block_list in grouped_blocks.items %}
<div class="fp-tab-pane {% if forloop.first %}active{% endif %}" id="{{ group|slugify }}">
<div class="fp-tab-pane {% if forloop.first %}active{% endif %}" id="{{ group|fp_slugify }}">
<ul class="fp-widget-list">
{% for fp_block in block_list %}
<li>
Expand Down
17 changes: 17 additions & 0 deletions fancypages/templatetags/fp_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django import template

from ..utils import unicode_slugify

register = template.Library()


@register.filter
def fp_slugify(value):
"""
Extends the default ``slugify`` filter provided in Django to work with
non-Ascii characters. The slugify function used uses ``unidecode`` before
applying the default slugifier. If Oscar is installed, however, the more
sophisticated slugifier in ``oscar.core.utils`` is used and the
``OSCAR_SLUG_MAP`` and ``OSCAR_SLUG_BLACKLIST`` are both respected.
"""
return unicode_slugify(value)
11 changes: 10 additions & 1 deletion fancypages/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from ..defaults import FP_PAGE_MODEL, FP_NODE_MODEL


FP_NODE_MODEL = getattr(settings, 'FP_NODE_MODEL', FP_NODE_MODEL)
FP_PAGE_MODEL = getattr(settings, 'FP_PAGE_MODEL', FP_PAGE_MODEL)

Expand Down Expand Up @@ -75,3 +74,13 @@ def loaddata(orm, fixture_name):
with patch('django.core.serializers.python._get_model', _get_model):
from django.core.management import call_command
call_command("loaddata", fixture_name)


try:
from oscar.core.utils import slugify as unicode_slugify
except ImportError:
from unidecode import unidecode
from django.template.defaultfilters import slugify

def unicode_slugify(value):
return slugify(unidecode(value))
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
install_requires=[
'Django>=1.5',
'South',
'unidecode',
'django-appconf',
'django-treebeard',
'django-model-utils',
Expand Down

0 comments on commit d3e6356

Please sign in to comment.