I want to know how to implement the following source code and template
sample they gave within the widget browser.
I reviewed over the checkbox widget, and I think it will be easier
using the widget than creating my own form in my template.
I am assuming this is supposed to go in the controller
class CheckBoxListDesc(CoreWD):
name = "CheckBox List"
for_widget = CheckBoxList("your_checkbox_list",
options=[(1, "Python"),
(2, "Java"),
(3, "Pascal"),
(4, "Ruby")],
default=[1,4])
and this in the template
<ul xmlns:py="http://purl.org/kid/ns#"
class="${field_class}"
id="${field_id}"
py:attrs="list_attrs"
>
<li py:for="value, desc, attrs in options">
<input type="checkbox"
name="${name}"
id="${field_id}_${value}"
value="${value}"
py:attrs="attrs"
/>
<label for="${field_id}_${value}" py:content="desc" />
</li>
</ul>
However I get a traceback error
Traceback (most recent call last):
File "/var/projects/document_site/se/start-se.py", line 27, in ?
from se.controllers import Root
File "/var/projects/document_site/se/se/controllers.py", line 75, in
?
class CheckBoxListDesc(CoreWD):
NameError: name 'CoreWD' is not defined
I need alot of help with this. I've been trying to use checkboxs within
my application but I have had NO SUCCESS. If someone is willing to help
me out it would be greatly appreciated.
Thank you
Stephen
Hi Stephen,
I will show you how to build a complete form containing even a
CheckBoxList, in your controller do something like this:
from turbogears import expose, validate, error_handler, flash, widgets,
validators
class MyFields(widgets.WidgetsList):
name = TextField()
email = TextField(validator=validators.Email())
language = CheckBoxList(options=[(1, "Python"), (2, "Java"), (3,
"Pascal"), (4, "Ruby")],
default=[1,4])
my_form = widgets.TableForm(fields=MyFields(), action="save")
now you need two methods methods attached to your controller in this
way:
@expose(template="test.new")
def new(self, tg_errors=None):
if tg_errors is not None:
flash("Please fix all errors")
return dict(my_form=my_form)
@expose()
@validate(form=my_form)
@error_handler(new)
def save(self, name, email, language):
#the data your received is valid and you can add it to the database
...
Hope this helps, keep in mind that when you look at a widget using the
widget browser the source code refers to the code running that example,
generally what you really need is the for_widget portion, the template
tab refers to the widget's template for further customization that
oftten is not needed.
Inside the turbogears's trac you can find a complete package that shows
how to use widgets (very easy example anyway), I have updated it to
work with the latest turbogears version (0.9a8), you can find it here:
Ciao
Michele
my_form = widgets.TableForm (fields=MyFields(), action="save")
now you need two methods methods attached to your controller in this
way:
@expose(template="test.new")
def new(self, tg_errors=None):
if tg_errors is not None:
flash("Please fix all errors")
return dict(my_form=my_form)
@expose()
@validate(form=my_form)
@error_handler(new)
def save(self, name, email, language):
#the data your received is valid and you can add it to the database
...
Hope this helps, keep in mind that when you look at a widget using the
widget browser the source code refers to the code running that example,
generally what you really need is the for_widget portion, the template
tab refers to the widget's template for further customization that
oftten is not needed.
Inside the turbogears's trac you can find a complete package that shows
how to use widgets (very easy example anyway), I have updated it to
work with the latest turbogears version (0.9a8), you can find it here:
http://trac.turbogears.org/turbogears/attachment/wiki/SimpleWidgetForm/FormsTutorial-0.9a8.tar.bz2?format=raw
Ciao
Michele
http://groups.google.com/group/turbogears/browse_thread/thread/35aefef01b4e1975/3fb7275ac2a60501
(and forgive me for those stupid misspelling mistakes)
Just to answer your question right now: you don't need to write any
WidgetDescription or CoreWD (which is a WidgetDescriptio btw)... These
2 classes are designed to show a sample of the widget (plus other
information) in the Toolbox Widget Browser.
I'd suggest the reading of this tutorial (try changing
"widgets.TextField" to "widgets.CheckBox") :
http://trac.turbogears.org/turbogears/wiki/SimpleWidgetForm
I hope it will help you. If no, just tell us... :)
Cheers,
Roger
PS: Maybe these videos from
http://www.turbogears.org/docs/devcasts.html can help you too...
On 7/31/06, OriginalBrownster <original...@gmail.com> wrote:
>
I will be trying to use these widgets to allow users to select files to
download from my database.
Contructing my own form and using simple checkboxs was causing me too
much difficulty
Thank you
I implented both your examples and found both to help me understand how
to use the wiget form.
my question for Nicky and perhaps Michelle also is: instead of using
**kw in Nicky's example to bring in what elements have been checked is
there another way to do so?
Also I fully do not understand the function of **kw.
For michelle example I'm sure this is done through the language
parameter in
def save(self, name, email, language):
however I didn't know how to user language to find out which had been
checked off.
Sorry for the inconvience, but I'm really new to turbogears widgets.
Thank you