Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. from unidecode import unidecode
  2. from django.conf import settings
  3. def slugify(value):
  4. """
  5. Slugify a string (even if it contains non-ASCII chars)
  6. """
  7. # Re-map some strings to avoid important characters being stripped. Eg
  8. # remap 'c++' to 'cpp' otherwise it will become 'c'.
  9. if hasattr(settings, 'OSCAR_SLUG_MAP'):
  10. for k, v in settings.OSCAR_SLUG_MAP.items():
  11. value = value.replace(k, v)
  12. # Allow an alternative slugify function to be specified
  13. if hasattr(settings, 'OSCAR_SLUG_FUNCTION'):
  14. slugifier = settings.OSCAR_SLUG_FUNCTION
  15. else:
  16. from django.template import defaultfilters
  17. slugifier = defaultfilters.slugify
  18. # Use unidecode to convert non-ASCII strings to ASCII equivalents where
  19. # possible.
  20. value = slugifier(
  21. unidecode(unicode(value)))
  22. # Remove stopwords
  23. if hasattr(settings, 'OSCAR_SLUG_BLACKLIST'):
  24. for word in settings.OSCAR_SLUG_BLACKLIST:
  25. value = value.replace(word + '-', '')
  26. value = value.replace('-' + word, '')
  27. return value
  28. def compose(*functions):
  29. """
  30. Compose functions
  31. This is useful for combining decorators.
  32. """
  33. def _composed(*args):
  34. for fn in functions:
  35. try:
  36. args = fn(*args)
  37. except TypeError:
  38. # args must be scalar so we don't try to expand it
  39. args = fn(args)
  40. return args
  41. return _composed