[Checkins] SVN: z3c.form/trunk/src/z3c/form/widget.py When calling a field's defaultFactory attribute, we need to do it for a field with its context binded

Roger dev at projekt01.ch
Sun Feb 10 07:55:18 UTC 2013


Hi Franco,

thanks for the improvement

I guess but didn't review this, your improvement should probably
check the ignoreContext marker and only bind the field if 
ignoreContext=False?

I have the feeling that bind a context with a Choice field 
could get into trouble depending on the vocabulary and term
lookup. e.g. add form etc.

But could be that I'm wrong. I'm really not sure it's just a feeling.


Regards
Roger Ineichen

> Betreff: [Checkins] SVN: z3c.form/trunk/src/z3c/form/widget.py When
calling a field's
> defaultFactory attribute, we need to do it for a field with its context
binded
> 
> Log message for revision 129241:
>   When calling a field's defaultFactory attribute, we need to do it for a
field with its
> context binded
> 
> Changed:
>   U   z3c.form/trunk/src/z3c/form/widget.py
> 
> -=-
> Modified: z3c.form/trunk/src/z3c/form/widget.py
> ================================================================
> ===
> --- z3c.form/trunk/src/z3c/form/widget.py	2013-02-09 16:53:51 UTC (rev
> 129240)
> +++ z3c.form/trunk/src/z3c/form/widget.py	2013-02-09 22:28:19 UTC (rev
> 129241)
> @@ -105,15 +105,18 @@
>                      (self.context, self.field),
>                      interfaces.IDataManager).query()
>              # Step 1.2.2: If we still do not have a value, we can always
use
> -            #             the default value of the field, id set
> +            #             the default value of the field, if set
>              # NOTE: It should check field.default is not missing_value,
but
>              # that requires fixing zope.schema first
> -            if ((value is self.field.missing_value or
> -                 value is interfaces.NO_VALUE) and
> -                self.field.default is not None and
> -                self.showDefault):
> -                value = self.field.default
> -                lookForDefault = True
> +            # We get a clone of the field with the context binded
> +            field = self.field.bind(self.context)
> +
> +            if value is field.missing_value or value is
interfaces.NO_VALUE:
> +                default_value = field.default
> +                if default_value is not None and self.showDefault:
> +                    value = field.default
> +                    lookForDefault = True
> +
>          # Step 1.3: If we still have not found a value, then we try to
get it
>          #           from an attribute value
>          if ((value is interfaces.NO_VALUE or lookForDefault)
> 
> _______________________________________________
> checkins mailing list
> checkins at zope.org
> https://mail.zope.org/mailman/listinfo/checkins




More information about the checkins mailing list