Question about Checkboxtable

0 views
Skip to first unread message

Ivo Looser

unread,
Jul 12, 2008, 8:02:36 AM7/12/08
to toscawidge...@googlegroups.com
Hi Together
 
First i have to say that you all do a very nice and great job with you Wiget library. I like to use it all the Time.
 
As deeper i digg in the Source far more Questions i get. I'm not a fulltime Python Developer because of that some parts are hard to understand for me...
 
I'm working with TW on Turbogears 1.0.5 on Windows and Macosx.
 
Ok, here are my Question:
 
I have to make a Users edit form with checkboxtable selection for Groups (Turbogears Identity). For that Form i have a field groups = CheckBoxTable(label_text='Gruppen:', options = getGroupOptions, template="myproject.admin.templates.checkboxtable", validator=Int(), num_cols=3, css_class="checkbox_table")
 
The getGroupOptions look like this.
 
def getGroupOptions():
    options = []
    gps = [g for g in session.query(Group)]
    return gps
 
Now i adaptet in the checkboxtable  value="${value}"  to value="${value.group_id}" and py:content="desc" to py:content="desc.display_name". That works great for me.
But is there a way to say outside from template what value from the groups object should displayed? I don't like to create custom templates if its not realy necessary.
 
I thougth there whould be a way with lambda but i can't find the solution.
 
Thank for you Help.
 
Ivo Looser
 
 
 

Alberto Valverde

unread,
Jul 12, 2008, 1:01:47 PM7/12/08
to toscawidge...@googlegroups.com
Ivo Looser wrote:
> Hi Together
>
> First i have to say that you all do a very nice and great job with you
> Wiget library. I like to use it all the Time.

Thanks :)


>
> As deeper i digg in the Source far more Questions i get. I'm not a
> fulltime Python Developer because of that some parts are hard to
> understand for me...
>
> I'm working with TW on Turbogears 1.0.5 on Windows and Macosx.
>
> Ok, here are my Question:
>
> I have to make a Users edit form with checkboxtable selection for
> Groups (Turbogears Identity). For that Form i have a field groups =
> CheckBoxTable(label_text='Gruppen:', options = getGroupOptions,
> template="myproject.admin.templates.checkboxtable", validator=Int(),
> num_cols=3, css_class="checkbox_table")
>
> The getGroupOptions look like this.
>
> def getGroupOptions():
> options = []
> gps = [g for g in session.query(Group)]
> return gps
>
> Now i adaptet in the checkboxtable value="${value}" to
> value="${value.group_id}" and py:content="desc" to
> py:content="desc.display_name". That works great for me.
> But is there a way to say outside from template what value from the
> groups object should displayed? I don't like to create custom
> templates if its not realy necessary.
>
> I thougth there whould be a way with lambda but i can't find the solution.

The RelatedFetcher validator in this recipe should do it:
http://toscawidgets.org/trac/tw.forms/wiki/FAQ#how-can-i-populate-a-singleselectfield-with-an-sqlalchemy-mapped-instance

Alberto

Ivo Looser

unread,
Jul 12, 2008, 2:16:14 PM7/12/08
to toscawidge...@googlegroups.com
Hi Alberto
 
Thanks for the quick response.
Thats looks exactly like the solution that i searched.
 
When i try to use the RelatedFetcher i got the error [1] it seems to be with FormEncode 1.0.1 and FormEncode Dev.
 
 
Have you an idea?
 
Thanks Ivo
 

Alberto Valverde

unread,
Jul 12, 2008, 3:04:00 PM7/12/08
to toscawidge...@googlegroups.com
Ivo Looser wrote:
> Hi Alberto
>
> Thanks for the quick response.
> Thats looks exactly like the solution that i searched.
>
> When i try to use the RelatedFetcher i got the error [1] it seems to
> be with FormEncode 1.0.1 and FormEncode Dev.

RelatedFetcher is a custom validator. You had the source right beneath
your eyes in the recipe I pointed you at ;)

Alberto

Alberto Valverde

unread,
Jul 13, 2008, 10:10:19 AM7/13/08
to toscawidge...@googlegroups.com
Ivo Looser wrote:
> Hi Alberto
>
> Thanks for the quick response.
> Thats looks exactly like the solution that i searched.
>
> When i try to use the RelatedFetcher i got the error [1] it seems to
> be with FormEncode 1.0.1 and FormEncode Dev.
>
> [1] http://paste.turbogears.org/paste/3192
>
> Have you an idea?

Oops, sorry, I spoke too fast. Ignore my previous tongue-in-cheek reply
please... :-ł
The problem I think is due to the _ translation function which FE
doens't like to be a lazystring. Do this before declaring the validator
(or remove the _ completely):

_ = lambda s: s

Translation should still work since FE filters all messages through a
translation function if it is provided to it.

Alberto

Reply all
Reply to author
Forward
0 new messages