Suggestions for new stuff in stdvars

0 views
Skip to first unread message

Dan Jacob

unread,
Nov 21, 2005, 2:36:10 AM11/21/05
to TurboGears
I was thinking of some useful functions/variables that could go into
stdvars

cycle(items, *args): generator that returns (index, item, looped_value)
like this:

<tr py:for="index, product, css_class in std.cycle(products, 'row_0',
'row_1')" py:attrs="class=css_class">
<td>...</td>
</tr>

produces:

<tr class="row_0">
<tr class="row_1">
<tr class="row_0">
etc.

errors: cherrypy.request.form_errors, or empty dict
inputs: cherrypy.request.form_inputs, or empty dict
require(permissions): returns True if current identity has
permission(s) e.g.

<a py:if="std.require('edit_news')" href="edit">Edit news item</a>

if_error(name, if_error_str, if_not_error_str=None): if
cherrypt.request.form_errors has "name" then return the error string,
if not return second string. Error string may be formatted with
%(error)s:

<label py:attrs="class=std.if_error('title', 'error')">Title
${std.if_error('title', ': %(error)s')}</label>

On an error this may produce:

<label class="error">Title : please enter a value</label>

Bob Ippolito

unread,
Nov 21, 2005, 10:15:01 AM11/21/05
to turbo...@googlegroups.com

On Nov 20, 2005, at 11:36 PM, Dan Jacob wrote:

>
> I was thinking of some useful functions/variables that could go into
> stdvars
>
> cycle(items, *args): generator that returns (index, item,
> looped_value)
> like this:
>
> <tr py:for="index, product, css_class in std.cycle(products, 'row_0',
> 'row_1')" py:attrs="class=css_class">
> <td>...</td>
> </tr>

cycle is a little confusing because it's in itertools.. here's how
that would be written as a generator with existing Python constructs
(of course you'd want to bring in the itertools stuff to a shorter
namespace).

itertools.izip(itertools.count(), products, itertools.cycle("row_0",
"row_1"))

-bob

Eric

unread,
Nov 21, 2005, 10:24:37 AM11/21/05
to turbo...@googlegroups.com
What is turbogears????

-------->-----Original Message-----
-------->From: turbo...@googlegroups.com
-------->[mailto:turbo...@googlegroups.com] On Behalf Of Bob Ippolito
-------->Sent: Monday, November 21, 2005 10:15 AM
-------->To: turbo...@googlegroups.com
-------->Subject: [TurboGears] Re: Suggestions for new stuff in stdvars
-------->
-------->
-------->
-------->On Nov 20, 2005, at 11:36 PM, Dan Jacob wrote:
-------->
-------->>
-------->> I was thinking of some useful functions/variables that could go
into
-------->> stdvars
-------->>
-------->> cycle(items, *args): generator that returns (index, item,
-------->> looped_value)
-------->> like this:
-------->>
-------->> <tr py:for="index, product, css_class in std.cycle(products,
'row_0',
-------->> 'row_1')" py:attrs="class=css_class">
-------->> <td>...</td>
-------->> </tr>
-------->
-------->cycle is a little confusing because it's in itertools.. here's how
-------->that would be written as a generator with existing Python
constructs
-------->(of course you'd want to bring in the itertools stuff to a shorter
-------->namespace).
-------->
-------->itertools.izip(itertools.count(), products,
itertools.cycle("row_0",
-------->"row_1"))
-------->
-------->-bob

dan...@gmail.com

unread,
Nov 29, 2005, 9:14:04 AM11/29/05
to TurboGears
I've opened a ticket on this. These generally seem like good ideas, but
I agree with Bob that we'll have to come up with something that doesn't
conceptually clash with what itertools gives you.

Kevin

dan...@gmail.com

unread,
Nov 29, 2005, 9:18:24 AM11/29/05
to TurboGears
Hi Eric,

> What is turbogears????

This question is puzzling in so many ways... this group has 750 members
and a lot of traffic... hard to imagine being in this group and not
knowing. Then, of course, there's Google:
http://www.google.com/search?q=turbogears

and, finally,

http://www.turbogears.org

Kevin

Reply all
Reply to author
Forward
0 new messages