Mercurial > public > src > rhodecode
comparison pylons_app/lib/helpers.py @ 0:564e40829f80
initial commit.
author | Marcin Kuzminski |
---|---|
date | Thu, 18 Feb 2010 13:01:57 +0100 |
parents | |
children | 2e1247e62c5b |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:564e40829f80 |
---|---|
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 """ | |
6 from routes import redirect_to, url_for | |
7 | |
8 from webhelpers.html import (literal, HTML, escape) | |
9 from webhelpers.html.tools import (auto_link, button_to, highlight, js_obfuscate | |
10 , mail_to, strip_links, strip_tags, tag_re) | |
11 from webhelpers.html.tags import (auto_discovery_link, checkbox, css_classes, | |
12 end_form, file, form, hidden, image, | |
13 javascript_link, link_to, link_to_if, | |
14 link_to_unless, ol, required_legend, | |
15 select, stylesheet_link, | |
16 submit, text, textarea, title, ul, xml_declaration) | |
17 from webhelpers.text import (chop_at, collapse, convert_accented_entities, | |
18 convert_misc_characters, convert_misc_entities, | |
19 lchop, plural, rchop, remove_formatting, replace_whitespace, | |
20 urlify) | |
21 | |
22 from webhelpers.pylonslib import Flash as _Flash | |
23 from webhelpers.pylonslib.secure_form import secure_form | |
24 | |
25 #Custom helper here :) | |
26 class _Link(object): | |
27 ''' | |
28 Make a url based on label and url with help of url_for | |
29 @param label:name of link if not defined url is used | |
30 @param url: the url for link | |
31 ''' | |
32 | |
33 def __call__(self, label = '', *url, **urlargs): | |
34 if label is None or '': | |
35 label = url | |
36 link_fn = link_to(label, url_for(*url, **urlargs)) | |
37 return link_fn | |
38 | |
39 | |
40 class _GetError(object): | |
41 | |
42 def __call__(self, field_name, form_errors): | |
43 tmpl = """<span class="error_msg">%s</span>""" | |
44 if form_errors and form_errors.has_key(field_name): | |
45 return literal(tmpl % form_errors.get(field_name)) | |
46 | |
47 link = _Link() | |
48 flash = _Flash() | |
49 get_error = _GetError() |