[Grok-dev] How do I get current day as default in interface schema definition?
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Tue Feb 17 07:19:32 EST 2009
On Tue, Feb 17, 2009 at 1:14 PM, Christian Klinger <cklinger at novareto.de> wrote:
> Sebastian Ware schrieb:
>> I am realising that the current schema definition default value is
>> useless since it is evaluated only at startup. Is there some way to
>> get grok to reevaluate the default value in a schema definition at
>> runtime? Or is there some other recommended way of passing the current
>> day as default to the add form?
>>
>> class IStory(Interface):
>>
>> publish_date = schema.Date(title=u'Publish Date', required = False,
>> default=date.today())
>>
>> Mvh Sebastian
> Hi Sebastian,
>
> you can use the setUpWidgets hook in your grok.Form.
>
> example:
> ---------
> from zope.formlib.form import setUpWidgets
>
>
> class AddForm(grokForm):
> ...
>
>
> def setUpWidgets(self, ignore_request=False):
> data={'publish_date': date.today()}
> self.adapters = {}
> self.widgets = setUpWidgets(
> self.form_fields,
> self.prefix,
> self.context,
> self.request,
> ignore_request=ignore_request,
> data=data)
As far as I can see, this would override whatever date was provided in
the form submit, right?
regards,
jw
More information about the Grok-dev
mailing list