[web2py][share] usefull snippet for enhance list of tags to be displayed in a table cell (or TD)

18 views
Skip to first unread message

Richard

unread,
Oct 22, 2015, 12:06:16 PM10/22/15
to web2py-users
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
Reply all
Reply to author
Forward
0 new messages