On Tue, May 16, 2006 at 06:46:16AM -0000, Michele Cella wrote:
>
> Jason Chu wrote:
> > I'm now trying to migrate our code from 0.9a4 to 0.9a6. Now if I do a
> > self.variable inside a widget and variable is callable, the
> > widget's metaclass will call variable() and return its value. Couple
> > that with widgets being callable and I can no longer pass references to
> > my internal widgets around.
> >
> > Where do I do this? Just about every custom edit form that we have.
> > We use params (used to be template_vars) to be able to refer to widgets
> > by name inside a template. Obviously, we also pass the widgets in
> > as the fields argument to the __init__ function so that value_for and
> > options_for still works.
> >
> > Here is an example:
> >
> > params = ['name', 'priority', 'duedate', 'duetime', 'summary',
> > 'description', 'completed', 'typeList']
> >
> > def __init__(self, *args, **kw):
> > self.priority =
> > widgets.SingleSelectField(name='Priority', options=...,
> > validator=...)
> > self.duedate =
> > CalendarDatePicker('Due Date')
> > self.summary = widgets.TextField(name='Summary',
> > validator=...)
> > self.description = widgets.TextArea(name='Description')
> > self.completed = widgets.CheckBox(name='Completed',
> > validator=...)
> > self.typeList =
> > TypeList(name='Types', numCols=1, options=model.getUserTags)
> >
> > fields =
> > [self.priority,self.duedate,self.summary,self.description,self.completed,self.typeList]
> >
> > super(TodoEditForm, self).__init__(fields=fields, *args, **kw)
> >
> > I've edited it for brevity, but you get the idea. The fields = [] part
> > is where I run into problems. Because self.priority is a callable,
> > it's called, and its value is returned instead of the reference to it.
> >
> > Before I go and change every reference to every widget in every form,
> > how exactly am I supposed to do something like this? I want to be able
> > to get to each of my widgets by some name inside the template, but
> > still have them play nicely with all the form stuff.
> >
>
> Hi Jason,
>
> you should not use "params" when you are working with widgets inside
> another widgets, this means you have a CompoundWidget and what you must
> use is "member_widgets" not "params".
>
> member_widgets works just like params but it doesn't handle callables
> automatically and you can override them only at init not
> render/display time, this makes sense since you're going to instantiate
> a widget during a request...
>
> http://trac.turbogears.org/turbogears/wiki/StatelessWidgets
>
> Ciao
> MicheleI can't remember why we didn't do it like this before... Does member_widgets play nice with fields=? No conflicts there? Jason -- If you understand, things are just as they are. If you do not understand, things are just as they are.
pgp0q4ECR0QWi.pgp
Description: PGP signature

