__init__.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. Smart slugify
  3. """
  4. import django.template.defaultfilters
  5. use_unidecode = True
  6. try:
  7. from unidecode import unidecode
  8. except ImportError:
  9. use_unidecode = False
  10. def slugify(string):
  11. if use_unidecode:
  12. string = unidecode(string)
  13. return django.template.defaultfilters.slugify(string)
  14. """
  15. Lazy translate that allows us to access original message
  16. """
  17. from django.utils import translation
  18. def ugettext_lazy(str):
  19. t = translation.ugettext_lazy(str)
  20. t.message = str
  21. return t
  22. def get_msgid(gettext):
  23. try:
  24. return gettext.message
  25. except AttributeError:
  26. return None
  27. """
  28. Random string
  29. """
  30. from django.utils import crypto
  31. def get_random_string(length):
  32. return crypto.get_random_string(length, "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM")
  33. """
  34. Date formats
  35. """
  36. from django.utils.formats import get_format
  37. formats = {
  38. 'DATE_FORMAT': '',
  39. 'DATETIME_FORMAT': '',
  40. 'TIME_FORMAT': '',
  41. 'YEAR_MONTH_FORMAT': '',
  42. 'MONTH_DAY_FORMAT': '',
  43. 'SHORT_DATE_FORMAT': '',
  44. 'SHORT_DATETIME_FORMAT': '',
  45. }
  46. for key in formats:
  47. formats[key] = get_format(key).replace('P', 'g:i a')