__init__.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.conf import settings
  31. from django.utils.importlib import import_module
  32. from misago import get_version
  33. try:
  34. locale_formats = import_module('django.conf.locale.%s.formats' % settings.LANGUAGE_CODE)
  35. formats = {
  36. 'DATE_FORMAT': locale_formats.DATE_FORMAT,
  37. 'TIME_FORMAT': locale_formats.TIME_FORMAT,
  38. 'DATETIME_FORMAT': locale_formats.DATETIME_FORMAT,
  39. 'SHORT_DATE_FORMAT': locale_formats.SHORT_DATE_FORMAT,
  40. 'SHORT_DATETIME_FORMAT': locale_formats.SHORT_DATETIME_FORMAT,
  41. }
  42. except (ImportError, AttributeError):
  43. formats = {
  44. 'DATE_FORMAT': settings.DATE_FORMAT,
  45. 'TIME_FORMAT': settings.TIME_FORMAT,
  46. 'DATETIME_FORMAT': settings.DATETIME_FORMAT,
  47. 'SHORT_DATE_FORMAT': settings.SHORT_DATE_FORMAT,
  48. 'SHORT_DATETIME_FORMAT': settings.SHORT_DATETIME_FORMAT,
  49. }
  50. formats['DATE_FORMAT'] = unicode(formats['DATE_FORMAT'].replace('P', 'g:i a'))
  51. formats['TIME_FORMAT'] = unicode(formats['TIME_FORMAT'].replace('P', 'g:i a'))
  52. formats['DATETIME_FORMAT'] = unicode(formats['DATETIME_FORMAT'].replace('P', 'g:i a'))
  53. formats['SHORT_DATE_FORMAT'] = unicode(formats['SHORT_DATE_FORMAT'].replace('P', 'g:i a'))
  54. formats['SHORT_DATETIME_FORMAT'] = unicode(formats['SHORT_DATETIME_FORMAT'].replace('P', 'g:i a'))