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

Christian Klinger cklinger at novareto.de
Tue Feb 17 09:28:03 EST 2009


Jan-Wijbrand Kolman schrieb:
> 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


Hi agin,

i think you are right, but if you use this in an AddForm i think this 
should work as expected.

- Christian



More information about the Grok-dev mailing list