[Grok-dev] How do I get current day as default in interface schema definition?

Steve Schmechel steveschmechel at yahoo.com
Tue Feb 17 08:41:57 EST 2009

I ran into this same problem and was confused by other examples I found in other sample code that are written like you suggest.

Don't these contradict the warning in the "Customising Fields in Grok" how-to, which explicitly states no to do something like this in your add form?  (It mostly warns about changing the field name, but setting the default is included in the example.)

See the "Further Information" section in:


--- On Tue, 2/17/09, Jan-Wijbrand Kolman <janwijbrand at gmail.com> wrote:

> From: Jan-Wijbrand Kolman <janwijbrand at gmail.com>
> Subject: Re: [Grok-dev] How do I get current day as default in interface schema definition?
> To: "Sebastian Ware" <sebastian at urbantalk.se>
> Cc: "Grok list" <grok-dev at zope.org>
> Date: Tuesday, February 17, 2009, 6:11 AM
> On Tue, Feb 17, 2009 at 12:41 PM, Sebastian Ware
> <sebastian at urbantalk.se> wrote:
> > 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?
> Something like this perhaps:
>   class MyAddForm(grok.AddForm):
>       ...
>       form_fields = grok.AutoFields(IMyInterface)
>       form_fields['mydatefield'].get_rendered =
> lambda x: datetime.date.today()
>       ...
> regards,
> jw
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev


More information about the Grok-dev mailing list