/kai/lib/helpers.py

https://bitbucket.org/bbangert/kai/ · Python · 45 lines · 42 code · 0 blank · 3 comment · 0 complexity · 4def95d13f5883387ccf3757034781e4 MD5 · raw file

  1. """Helper functions
  2. Consists of functions to typically be used within templates, but also
  3. available to Controllers. This module is available to both as 'h'.
  4. """
  5. import datetime
  6. import xml.utils.iso8601 as iso8601
  7. from docutils.core import publish_parts
  8. from webhelpers.date import distance_of_time_in_words
  9. from webhelpers.html.converters import textilize
  10. from webhelpers.html.tags import auto_discovery_link, link_to, select, stylesheet_link
  11. from webhelpers.text import truncate
  12. from webhelpers.pylonslib import Flash as _Flash
  13. from webhelpers.pylonslib.secure_form import auth_token_hidden_field
  14. from webob.exc import strip_tags
  15. from kai.lib.highlight import code_highlight, langdict
  16. success_flash = _Flash('success')
  17. failure_flash = _Flash('failure')
  18. def load_stylesheet_assets():
  19. import pylons
  20. import os
  21. path = os.path.join(pylons.config['pylons.paths']['static_files'], 'css',
  22. 'CSSLIST')
  23. f = open(path,'r')
  24. stylesheets = f.read()
  25. f.close()
  26. return ['/css/%s.css' % f for f in stylesheets.split()]
  27. def parse_iso_date(iso_date):
  28. return datetime.datetime.fromtimestamp(iso8601.parse(iso_date))
  29. def rst_render(content):
  30. defaults = {
  31. 'file_insertion_enabled': 0,
  32. 'raw_enabled': 0,
  33. 'input_encoding': 'unicode',
  34. 'halt_level': 7,
  35. }
  36. return publish_parts(content, writer_name='html',
  37. settings_overrides=defaults)['html_body']