[Zope3-Users] Re: Default value for an interface attribute
Maciej Wisniowski
maciej.wisniowski at coig.katowice.pl
Mon Mar 12 03:18:17 EDT 2007
>>> How about checking whether the value of 'default' is a
>>> callable and if so call it to obtain the default value.
>>>
>> Yup... but evaluation of this is done internally by Zope schema
>> package in Field class I think. Seems for me that there is no way
>> to define 'default' as callable.
>>
>
> Right. This is an unsupported use case. I bet if someone writes up a
> proposal and brings it up to discussion on zope3-dev at zope.org we'll find
> a common solution to this.
>
> Please also notice that we're moving to using launchpad more heavily. So
> if you write a proposal in the wiki, please also submit it as a feature
> request (blue print) in launchpad for the Zope 3 product.
I was playing a bit more with this issue and I realized that formlib
fields have 'get_rendered' method which is called to get default
values for a field. It is described at 'Computing default values'
section in formlib/form.txt.
Example from form.txt:
>>> class MyAddForm(form.AddFormBase):
... actions = ()
...
... def now(self):
... return datetime.datetime(2002, 12, 2, 12, 30)
...
... form_fields = form.Fields(
... form.Fields(IOrder).omit('now'),
... form.Field(IOrder['now'], get_rendered=now),
... )
...
... def setUpWidgets(self, ignore_request=True):
... super(MyAddForm, self).setUpWidgets(ignore_request)
--
Maciej Wisniowski
More information about the Zope3-users
mailing list