|
@@ -1,11 +1,23 @@
|
1
|
|
-from __future__ import absolute_import # for import below
|
2
|
|
-import six
|
|
1
|
+from __future__ import absolute_import # for logging import below
|
3
|
2
|
import logging
|
|
3
|
+import six
|
4
|
4
|
|
5
|
5
|
from django.utils.timezone import get_current_timezone, is_naive, make_aware
|
6
|
|
-from unidecode import unidecode
|
7
|
6
|
from django.conf import settings
|
8
|
|
-from django.template.defaultfilters import date as date_filter
|
|
7
|
+from django.template.defaultfilters import (date as date_filter,
|
|
8
|
+ slugify as django_slugify)
|
|
9
|
+from unidecode import unidecode
|
|
10
|
+
|
|
11
|
+from oscar.core.loading import import_string
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+def default_slugifier(value):
|
|
15
|
+ """
|
|
16
|
+ Oscar's default slugifier function.
|
|
17
|
+ Uses Django's slugify function, but first applies unidecode() to convert
|
|
18
|
+ non-ASCII strings to ASCII equivalents where possible.
|
|
19
|
+ """
|
|
20
|
+ return django_slugify(value)
|
9
|
21
|
|
10
|
22
|
|
11
|
23
|
def slugify(value):
|
|
@@ -18,11 +30,10 @@ def slugify(value):
|
18
|
30
|
value = value.replace(k, v)
|
19
|
31
|
|
20
|
32
|
# Allow an alternative slugify function to be specified
|
21
|
|
- if hasattr(settings, 'OSCAR_SLUG_FUNCTION'):
|
22
|
|
- slugifier = settings.OSCAR_SLUG_FUNCTION
|
23
|
|
- else:
|
24
|
|
- from django.template import defaultfilters
|
25
|
|
- slugifier = defaultfilters.slugify
|
|
33
|
+ # Recommended way to specify a function is as a string
|
|
34
|
+ slugifier = getattr(settings, 'OSCAR_SLUG_FUNCTION', default_slugifier)
|
|
35
|
+ if isinstance(slugifier, six.string_types):
|
|
36
|
+ slugifier = import_string(slugifier)
|
26
|
37
|
|
27
|
38
|
# Use unidecode to convert non-ASCII strings to ASCII equivalents where
|
28
|
39
|
# possible.
|