app_globals.py 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. from markupsafe import escape_silent as escape
  3. import tg
  4. from tracim.lib.utils import lazy_ugettext as l_
  5. from tg.flash import TGFlash
  6. """The application's Globals object"""
  7. __all__ = ['Globals']
  8. class Globals(object):
  9. """Container for objects available throughout the life of the application.
  10. One instance of Globals is created during application initialization and
  11. is available during requests via the 'app_globals' variable.
  12. """
  13. def __init__(self):
  14. """Do nothing, by default."""
  15. pass
  16. VERSION_NUMBER = '1.1.0'
  17. SHORT_DATE_FORMAT = l_('%B %d at %I:%M%p')
  18. class LinkReadyTGFlash(TGFlash):
  19. """
  20. This class inherits from (and is used in place of) TGFlash
  21. in order to allow to include links in flash messages.
  22. """
  23. def _render_static_version(self, container_id):
  24. payload = self.pop_payload()
  25. if not payload:
  26. return ''
  27. # HACK - THIS IS A PATCH
  28. if payload.get('no_escape'):
  29. payload['message'] = payload.get('message','')
  30. else:
  31. payload['message'] = escape(payload.get('message',''))
  32. payload['container_id'] = container_id
  33. return self.static_template.substitute(payload)
  34. # Override the default flash with the Specific one
  35. tg.flash = LinkReadyTGFlash.create_global()