ToscaWidgets2 Booleans

53 views
Skip to first unread message

Yoann Mouscaz

unread,
Mar 27, 2013, 10:52:04 AM3/27/13
to toscawidge...@googlegroups.com
Hi guys,

I encounter a little problem with my checkbox fields... They give me as result the values 'on' (for True) and None (for False).
So if the value is None,in my controller my keyword doesn't exist and I can't catch it in my 'post' function...

Illustration with an example :

* In my widget :

twf.CheckBox(id="url", label_text="I want to upload the file from this URL : ", help_text="tick it if you want to download it in the application")

* In my controller :

for k in kw:
    print k

---> and if 'url' is False (None with the new system...), 'url' doesn't exist... And it's problematic for dynamic form with dynamic fields....

Can anyone is able to help me to convert this new boolean value system to the good old boolean system.

Thanks a lot,


Yoann


Paul Johnston

unread,
Mar 27, 2013, 11:13:44 AM3/27/13
to toscawidge...@googlegroups.com
Hi,

You are using the raw values from the request; to get the behaviour you want you need to feed these through the validators. Have a look at the tutorial to see how.

Paul


Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "ToscaWidgets-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-dis...@googlegroups.com.
To post to this group, send email to toscawidge...@googlegroups.com.
Visit this group at http://groups.google.com/group/toscawidgets-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Yoann Mouscaz

unread,
Mar 27, 2013, 11:30:32 AM3/27/13
to toscawidge...@googlegroups.com
Ok, but can you attach the link of this tutorial please ?
I check here and here but nothing for my pb...
Thx a lot

Yoann


Le mercredi 27 mars 2013 16:13:44 UTC+1, Paul Johnston a écrit :
Hi,

You are using the raw values from the request; to get the behaviour you want you need to feed these through the validators. Have a look at the tutorial to see how.

Paul


Sent from my iPhone

On 27 Mar 2013, at 14:52, Yoann Mouscaz <mou...@hotmail.fr> wrote:

Hi guys,

I encounter a little problem with my checkbox fields... They give me as result the values 'on' (for True) and None (for False).
So if the value is None,in my controller my keyword doesn't exist and I can't catch it in my 'post' function...

Illustration with an example :

* In my widget :

twf.CheckBox(id="url", label_text="I want to upload the file from this URL : ", help_text="tick it if you want to download it in the application")

* In my controller :

for k in kw:
    print k

---> and if 'url' is False (None with the new system...), 'url' doesn't exist... And it's problematic for dynamic form with dynamic fields....

Can anyone is able to help me to convert this new boolean value system to the good old boolean system.

Thanks a lot,


Yoann


--
You received this message because you are subscribed to the Google Groups "ToscaWidgets-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-discuss+unsub...@googlegroups.com.

Moritz Schlarb

unread,
Mar 27, 2013, 12:14:38 PM3/27/13
to toscawidge...@googlegroups.com

Yoann Mouscaz

unread,
Mar 27, 2013, 12:31:11 PM3/27/13
to toscawidge...@googlegroups.com
I saw "4 answers" but only 3 are displayed... Maybe this post will unlock the fourth ...

Moritz Schlarb

unread,
Mar 27, 2013, 1:21:10 PM3/27/13
to toscawidge...@googlegroups.com
Yeah, well, personally, I kinda hate the Google Groups interface very much... :D
If you still don't see it, I just posted this link:

Yoann Mouscaz

unread,
Mar 28, 2013, 4:51:46 AM3/28/13
to toscawidge...@googlegroups.com
HI,

thanks for your answer.
I'm really not sure that it will fix my pb :/
I just want to came back to the classical values for a boolean widget : True and False. I don't want these 'on' and None values... It's just horrible to catch them in something which is dynamical...
Moreover, I didn't mention it before but I'm using Turbogears 2.1.5 with TW2...if it can help you...
Can you just tell me if the value 'on' and None are "normal"....

Thanks a lot

Yoann

Moritz Schlarb

unread,
Mar 28, 2013, 9:53:58 AM3/28/13
to toscawidge...@googlegroups.com
Hi Yoann,

well, in HTML forms, checkboxes work that way - if they are checked, their value gets submitted, if they aren't, nothing gets submitted - not even the name of the form element.
Regarding what Paul already said: The validators will transform this information (or non-information) into what you want: Python True or False.

Maybe you can show us your code and we can show you what this means.

Cheers,
Moritz 

Paul Johnston

unread,
Mar 28, 2013, 10:01:14 AM3/28/13
to toscawidge...@googlegroups.com
Hi,

So you are using TW2 with TG. I just checked over that tutorial, and it doesn't actually explain how to do validation. It should do - but I'm not the right person to do this - I don't use TG now.

As a simple first step, in your controller method do this:

data = MyFormWidget.validate(kw)

After this, data will hold the validated values - the True/False you want from the checkbox.

You should be aware that validation can raise an exception - if data is invalid. I think there is a neat way to catch this using a TG decorator, but I can't remember it offhand.

Paul



To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-dis...@googlegroups.com.

Yoann Mouscaz

unread,
Mar 28, 2013, 10:48:32 AM3/28/13
to toscawidge...@googlegroups.com
Hi,

First, thanks to both of you.

Actually I fixed my problem with a quick and dirty method because unfortunatly I haven't the time to search/wait more. :)
My method : I check in my post method (in controller) if kw are registred in my db as "checkbox" widget. If it one is found (it exists, first) so it is equals to "on" and so I save it into my db as True. Then for the "Falses" I match the kw_list with the checkbox_widgets_list. All which are not in the kw_list are considered as False and registred as in my db.

Thanks for your help, it's really pleasant to be helped in these kind of situations... :)
Have a nice Easter week end !

Yoann
To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-discuss+unsubscrib...@googlegroups.com.
To post to this group, send email to toscawidge...@googlegroups.com.

Moritz Schlarb

unread,
Mar 28, 2013, 11:23:02 AM3/28/13
to toscawidge...@googlegroups.com
After checking it, too, I think that the tutorial doesn't quite use the "TurboGears"-way of handling widgets...
E.g. I thought tw2.forms.FormPage is more useful in a standalone environment. Also, w.fetch_data(request) seems a little odd to me...

Compare it to https://turbogears.readthedocs.org/en/rtfd2.2.2//main/TwForms.html, there is an example with the @validate decorator...
To unsubscribe from this group and stop receiving emails from it, send an email to toscawidgets-discuss+unsubscrib...@googlegroups.com.
To post to this group, send email to toscawidge...@googlegroups.com.

Paul Johnston

unread,
Mar 28, 2013, 11:26:22 AM3/28/13
to toscawidge...@googlegroups.com
Hi,

Compare it to https://turbogears.readthedocs.org/en/rtfd2.2.2//main/TwForms.html, there is an example with the @validate decorator...

Aha! This is the tutorial I was thinking of. Yes, it is a better description of how to do the basics in a way that plays nice with TurboGears.

Paul
Reply all
Reply to author
Forward
0 new messages