[Erp5-dev] Property default on string and StringField behavoiur

Jean-Paul Smets jp at nexedi.com
Wed Jun 20 11:32:25 CEST 2007


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.

 
Łukasz Nowak a écrit :
> 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
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Erp5-dev mailing list
> Erp5-dev at erp5.org
> http://erp5.org/mailman/listinfo/erp5-dev




More information about the Erp5-dev mailing list