Re: [Zope3-Users] Re: Default value for an interface attribute

2007-03-12 Thread Maciej Wisniowski

 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
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


[Zope3-Users] Re: Default value for an interface attribute

2007-03-01 Thread Raphael Ritz

Maciej Wisniowski schrieb:

I have this interface:

class INews(IPage):
A news page for the application.


date = Date(
title=_(uPublication Date),
description=_(uThe intended date for this news),
default=date.today(),
required=False
)
  

With formlib (in Five in fact, not with Zope3) I was creating
form_fields that should have dynamic defaults in __call__
method of formlib's AddForm (EditForm)
view. I think it is not nice solution so I'd love to see
better way of doing this.



How about checking whether the value of 'default' is a
callable and if so call it to obtain the default value.
That way

   defautl=date.today

(without the ())should do what Douglas expects (maybe
this is even the case already?).

Not that you want to know this but in Archetypes we explicitly
support 'default' and 'default_method' as field properties.
If no 'default' is provided, 'default_method' is looked up and
if it exists it's called.

Raphael

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Default value for an interface attribute

2007-03-01 Thread Douglas Douglas

--- Raphael Ritz [EMAIL PROTECTED] wrote:

 How about checking whether the value of 'default' is a
 callable and if so call it to obtain the default value.
 That way
 
 defautl=date.today
 
 (without the ())should do what Douglas expects (maybe
 this is even the case already?).
 

I tried this way, but raises this Exception:

ConfigurationError: ('Invalid value for', 'interface', (built-in method today
of type object at 0xb79465c0, type 'datetime.date'))



 

Now that's room service!  Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
http://farechase.yahoo.com/promo-generic-14795097
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Default value for an interface attribute

2007-03-01 Thread Maciej Wisniowski

 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.

-- 
Maciej Wisniowski
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Re: Default value for an interface attribute

2007-03-01 Thread Christian Theune
Hi,

Am Donnerstag, den 01.03.2007, 16:54 +0100 schrieb Maciej Wisniowski:
  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.

Christian

-- 
gocept gmbh  co. kg - forsterstraße 29 - 06112 halle/saale - germany
www.gocept.com - [EMAIL PROTECTED] - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users