You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.py 879B

123456789101112131415161718192021222324
  1. from unidecode import unidecode
  2. from django.template import defaultfilters
  3. from django.conf import settings
  4. def slugify(value):
  5. """
  6. Slugify a string (even if it contains non-ASCII chars)
  7. """
  8. # Re-map some strings to avoid important characters being stripped. Eg
  9. # remap 'c++' to 'cpp' otherwise it will become 'c'.
  10. if hasattr(settings, 'OSCAR_SLUG_MAP'):
  11. for k, v in settings.OSCAR_SLUG_MAP.items():
  12. value = value.replace(k, v)
  13. # Use unidecode to convert non-ASCII strings to ASCII equivalents where
  14. # possible.
  15. value = defaultfilters.slugify(
  16. unidecode(unicode(value)))
  17. # Remove stopwords
  18. if hasattr(settings, 'OSCAR_SLUG_BLACKLIST'):
  19. for word in settings.OSCAR_SLUG_BLACKLIST:
  20. value = value.replace(word + '-', '')
  21. value = value.replace('-' + word, '')
  22. return value