PageRenderTime 157ms CodeModel.GetById 50ms app.highlight 15ms RepoModel.GetById 86ms app.codeStats 0ms

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