Discussion:
[Erp5-dev] Property default on string and StringField behavoiur
Łukasz Nowak
2007-06-20 09:23:13 UTC
Permalink
Hello,

I created PropertySheet as attached. Associated it with Organisation
portal type.

Created new organisation, invoked scripts:
print repr(context.getVentis())
print repr(context.getProperty('ventis'))

shows:
''
''

Now added StringField my_ventis to Organisation_view. Put data in it
'some data', above script returns:
'data'
'data'

Removed string from widget, updated form, now above script returns:
None
None

I was comparing objects with them default value ('') all the time and
workaround it with comparing to '' and None. But I thought, that after
reseting value it will become default from PropertySheet and not None...

Is it my error, bug or feature? Is it documented anywhere?

Luke
--
?ukasz Nowak R&D Ventis http://www.ventis.com.pl/
tel: +48 32 768 16 85 fax: +48 32 392 10 61
``Use the Source, Luke...''

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Ventis.py
Type: text/x-python
Size: 252 bytes
Desc: not available
URL: <http://mail.tiolive.com/pipermail/erp5-dev/attachments/20070620/4692e707/attachment.py>
Jean-Paul Smets
2007-06-20 09:32:25 UTC
Permalink
Hi,

Although I did not look into it carefully, here is my guess:
1- if you provide an empty string to the StringField, it sets the
property to None
2- since a property is set, the default will not be used in the
accessor and None is returned

Probably, if you remove the property (set to None) on the object, the
accessor will return '' again.

The question you raise is after all the following : which property
should the StringField set on a object when the user provides an empty
string ?
- None (current situation apparently)
- '' (what you were expecting)
- remove the default property (this one would for example end up
showing acquired values)

The current approach therefore to say that, if the user enters an empty
string, it means that he wants no property set for that property.
For example, if you enter an empty string in a float field, it means you
want no value defined on the object (and not 0.0).
I think that for consistency, it should be the same for strings.

But if you have a better idea, let me know.

Regards,

JPS.
Post by Łukasz Nowak
Hello,
I created PropertySheet as attached. Associated it with Organisation
portal type.
print repr(context.getVentis())
print repr(context.getProperty('ventis'))
''
''
Now added StringField my_ventis to Organisation_view. Put data in it
'data'
'data'
None
None
I was comparing objects with them default value ('') all the time and
workaround it with comparing to '' and None. But I thought, that after
reseting value it will become default from PropertySheet and not None...
Is it my error, bug or feature? Is it documented anywhere?
Luke
------------------------------------------------------------------------
_______________________________________________
Erp5-dev mailing list
Erp5-dev at erp5.org
http://erp5.org/mailman/listinfo/erp5-dev
Loading...