Hello,
When building from scratch an HTML Table with web2py helper I found myself
needing to split list of A() tags with CAT(', ') tag to proper display of
tags list in HTML.
So, I have write this little snippet that I found usefull for that :
def cat_comma_snippet(tag_to_be_split_with_cat_comma):
"""
Take a iterable list of web2py tag(s) and return tags splitted with
CAT(', ')
"""
tags_with_cat = []
if len(tag_to_be_split_with_cat_comma) > 1:
for i, l in enumerate(tag_to_be_split_with_cat_comma):
if i + 1 < len(tag_to_be_split_with_cat_comma):
tags_with_cat.extend([l, CAT(', ')])
else:
tags_with_cat.append(l)
else:
tags_with_cat = tag_to_be_split_with_cat_comma
return tags_with_cat
You can pass it this :
[A('item1_represent', _href=URL('controller', 'function', args='agrs', vars=
dict(record_id=1)), A('item2_represent', _href=URL('controller', 'function',
args='agrs', vars=dict(record_id=2)), ...]
And it will return :
[A('item1_represent', _href=URL('controller', 'function', args='agrs', vars=
dict(record_id=1)), CAT(', '), A('item2_represent', _href=URL('controller',
'function', args='agrs', vars=dict(record_id=2)), ...]
Enjoy...
Richard
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.