0
|
1 """Helper functions
|
|
2
|
|
3 Consists of functions to typically be used within templates, but also
|
|
4 available to Controllers. This module is available to both as 'h'.
|
|
5 """
|
43
|
6 from pylons import url
|
0
|
7 from webhelpers.html import (literal, HTML, escape)
|
|
8 from webhelpers.html.tools import (auto_link, button_to, highlight, js_obfuscate
|
|
9 , mail_to, strip_links, strip_tags, tag_re)
|
|
10 from webhelpers.html.tags import (auto_discovery_link, checkbox, css_classes,
|
|
11 end_form, file, form, hidden, image,
|
|
12 javascript_link, link_to, link_to_if,
|
|
13 link_to_unless, ol, required_legend,
|
|
14 select, stylesheet_link,
|
45
|
15 submit, text, password, textarea, title, ul, xml_declaration)
|
0
|
16 from webhelpers.text import (chop_at, collapse, convert_accented_entities,
|
|
17 convert_misc_characters, convert_misc_entities,
|
|
18 lchop, plural, rchop, remove_formatting, replace_whitespace,
|
|
19 urlify)
|
|
20
|
|
21 from webhelpers.pylonslib import Flash as _Flash
|
|
22 from webhelpers.pylonslib.secure_form import secure_form
|
|
23
|
|
24 #Custom helper here :)
|
|
25 class _Link(object):
|
|
26 '''
|
|
27 Make a url based on label and url with help of url_for
|
|
28 @param label:name of link if not defined url is used
|
|
29 @param url: the url for link
|
|
30 '''
|
|
31
|
43
|
32 def __call__(self, label='', *url_, **urlargs):
|
0
|
33 if label is None or '':
|
|
34 label = url
|
43
|
35 link_fn = link_to(label, url(*url_, **urlargs))
|
0
|
36 return link_fn
|
|
37
|
|
38
|
|
39 class _GetError(object):
|
|
40
|
|
41 def __call__(self, field_name, form_errors):
|
|
42 tmpl = """<span class="error_msg">%s</span>"""
|
|
43 if form_errors and form_errors.has_key(field_name):
|
|
44 return literal(tmpl % form_errors.get(field_name))
|
|
45
|
|
46 link = _Link()
|
|
47 flash = _Flash()
|
|
48 get_error = _GetError()
|