On 10 juin, 19:05, Christoph Zwerschke <[email protected]> wrote:
> Am 10.06.2010 16:49 schrieb aspineux:
>
> > When displaying the query in a table, I want to display a custom
> > message if the result is empty.
>
> In TG 1.x you could use tg.ipeek for 
> that:http://docs.turbogears.org/1.0/stdvars

Yesssssssss !
Thanks

I works ! I cut&pasted the source

def ipeek(it):
    """Lets you look at the first item in an iterator.

    This is a good way to verify that the iterator actually contains
something.
    This is useful for cases where you will choose not to display a
list or
    table if there is no data present.

    """
    it = iter(it)
    try:
        item = it.next()
        return itertools.chain([item], it)
    except StopIteration:
        return None


in my  controller :

return dict(...
                elements=ipeek(elements),
               ...)


in my template :

<p py:if="not elements">The list is empty</p>
<table py:if="elements">
 <tr><th>Name</th></tr>
 <tr py:for="elem in elements"><td>${elem.name}</td></tr>
</table>



Regards

--
Alain Spineux                   |  aspineux gmail com
Your email 100% available |  http://www.emailgency.com
Send backup mail report    | http://www.magikmon.com/mkbackup



>
> Unfortunately, TG 2.x doesn't seem to provide anything similar.
>
> -- Christoph

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to