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.

Jason

Attachment: signature.asc
Description: PGP signature

Reply via email to