__init__.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. Date formats
  29. """
  30. from django.utils.formats import get_format
  31. formats = {
  32. 'DATE_FORMAT': '',
  33. 'DATETIME_FORMAT': '',
  34. 'TIME_FORMAT': '',
  35. 'YEAR_MONTH_FORMAT': '',
  36. 'MONTH_DAY_FORMAT': '',
  37. 'SHORT_DATE_FORMAT': '',
  38. 'SHORT_DATETIME_FORMAT': '',
  39. }
  40. for key in formats:
  41. formats[key] = get_format(key).replace('P', 'g:i a')