Explorar el Código

Support other slugifier function

master
Georgiy Kutsurua hace 13 años
padre
commit
6dcff660de
Se han modificado 2 ficheros con 23 adiciones y 2 borrados
  1. 12
    0
      docs/source/ref/settings.rst
  2. 11
    2
      oscar/core/utils.py

+ 12
- 0
docs/source/ref/settings.rst Ver fichero

259
 
259
 
260
 Default: ``/tmp``
260
 Default: ``/tmp``
261
 
261
 
262
+OSCAR_SLUG_FUNCTION
263
+-----------------
264
+
265
+Default: django.template.defaultfilters.slugify
266
+
267
+Slugify function
268
+
269
+Example:
270
+    def some_slugify(value)
271
+        pass
272
+    OSCAR_SLUG_FUNCTION = some_slugify
273
+
262
 Deprecated settings
274
 Deprecated settings
263
 ===================
275
 ===================
264
 
276
 

+ 11
- 2
oscar/core/utils.py Ver fichero

1
 from unidecode import unidecode
1
 from unidecode import unidecode
2
-from django.template import defaultfilters
3
 from django.conf import settings
2
 from django.conf import settings
4
 
3
 
5
 
4
 
12
     if hasattr(settings, 'OSCAR_SLUG_MAP'):
11
     if hasattr(settings, 'OSCAR_SLUG_MAP'):
13
         for k, v in settings.OSCAR_SLUG_MAP.items():
12
         for k, v in settings.OSCAR_SLUG_MAP.items():
14
             value = value.replace(k, v)
13
             value = value.replace(k, v)
14
+
15
+    # Allow an alternative slugify function to be specified
16
+    if hasattr(settings, 'OSCAR_SLUG_FUNCTION'):
17
+        slugifier = settings.OSCAR_SLUG_FUNCTION
18
+    else:
19
+        from django.template import defaultfilters
20
+        slugifier = defaultfilters.slugify
21
+
15
     # Use unidecode to convert non-ASCII strings to ASCII equivalents where
22
     # Use unidecode to convert non-ASCII strings to ASCII equivalents where
16
     # possible.
23
     # possible.
17
-    value = defaultfilters.slugify(
24
+    value = slugifier(
18
         unidecode(unicode(value)))
25
         unidecode(unicode(value)))
26
+
19
     # Remove stopwords
27
     # Remove stopwords
20
     if hasattr(settings, 'OSCAR_SLUG_BLACKLIST'):
28
     if hasattr(settings, 'OSCAR_SLUG_BLACKLIST'):
21
         for word in settings.OSCAR_SLUG_BLACKLIST:
29
         for word in settings.OSCAR_SLUG_BLACKLIST:
22
             value = value.replace(word + '-', '')
30
             value = value.replace(word + '-', '')
23
             value = value.replace('-' + word, '')
31
             value = value.replace('-' + word, '')
32
+
24
     return value
33
     return value

Loading…
Cancelar
Guardar