Mercurial > public > src > rhodecode
annotate pylons_app/lib/helpers.py @ 94:0bb9391bc287
webhelpers update
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 24 Apr 2010 16:52:34 +0200 |
parents | a886f5eba757 |
children | be0096a02772 |
rev | line source |
---|---|
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, | |
94
0bb9391bc287
webhelpers update
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
15 submit, text, password, textarea, title, |
0bb9391bc287
webhelpers update
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
16 ul, xml_declaration) |
0 | 17 from webhelpers.text import (chop_at, collapse, convert_accented_entities, |
94
0bb9391bc287
webhelpers update
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
18 convert_misc_entities, lchop, plural, rchop, |
0bb9391bc287
webhelpers update
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
19 remove_formatting, replace_whitespace, urlify) |
0 | 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() |