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

Christian Klinger cklinger at novareto.de
Tue Feb 17 07:14:49 EST 2009


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)

HTH

Christian



More information about the Grok-dev mailing list