>>> 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@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
Zope3-users mailing list

Reply via email to