[Product-Developers] Default value for fields introduced through a behavior

Malthe Borch mborch at gmail.com
Fri Nov 16 08:17:17 UTC 2012


This has already been fixed (or added, if you will):

https://github.com/plone/plone.dexterity/commit/dd491480b869bbe21ee50ef413c263705af7b170

\malthe

On 16 November 2012 09:03, Andreas Jung <lists at zopyx.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I have a Dexterity-based content-type that uses the following
> behavior:
>
> class IProductSelection2L(form.Schema):
>
>     form.fieldset(
>         'product_selection2l',
>         label=u'Produktauswahl',
>         fields=['product_selection2l'],
>         )
>
>     product_selection2l = schema.List(title=u'Produktauswahl',
> value_type=schema.TextLine())
>     form.widget(product_selection2l=ProductGroupsWidgetFactory)
>
> alsoProvides(IProductSelection2L, IFormFieldProvider)
>
> class ProductSelection2L(object):
>     adapts(IDexterityContent)
>
>     def __init__(self, context):
>         self.context = context
>
>     def _get_product_selection2l(self):
>         return self.context.product_selection2l or []
>     def _set_product_selection2l(self, value):
>         self.context.product_selection2l = value
>     product_selection2l = property(_get_product_selection2l,
> _set_product_selection2l)
>
>
> Obviously instances of my type using the behavior created
> through invokeFactory() do not have the 'product_selection2l'
> property automatically. How do you initialize a Dexterity type
> properly in order to have all properties introduced by behavior
> initialized properly? The workaround right now is to define
> 'product_selection2l' as a class-level variable in my content class but
> this is only a weird workaround...how to do that properly?
>
> Andreas
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (Darwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iQGUBAEBAgAGBQJQpfNnAAoJEADcfz7u4AZjFTULv3YY/0idRK3LZHm/6THnAj+S
> vyTI/a9erX9idbKnoQ4v30qRylVhqpViKwRQHeAoUtV6q++g0PuOyRGnXKKtC3xi
> o6p7WpGHsrq98NztFx/h90uDIv2doc/VnFLwLOxeip83C3nYnURwILWkCLcf4xww
> ho5/OucscepCxRzSnu1NJL+tHhdgRcYWax4Q//6cbiTtJnVPbr27EOAYUEJHQ9BP
> 6IIn0kYVW06zzcDRP8guM1013KwM9w1PqmpKEX2fGfoDSvq02SFKbWuJWjA7pcKd
> cO+pOrzQcCuI8kpY42HsOydMSvS+39YBiwjjk58dShL9Li8UlgvJjKyrvWvXjY8V
> Z/4nP6bVmmBaCRUtUaWURBzUYw6BXlhN2MEPLsgtdrEqB83dhCelkv3gTPAF24bV
> muKlZy3onoUA556zfROotp3Q0nqCJgLe25cxdMvJEkW82APTm038biAfrjYw6qwX
> XfF0wHuXSmQcJkcPGGYpBoJvQ97dyX0=
> =YFK9
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Product-Developers mailing list
> Product-Developers at lists.plone.org
> https://lists.plone.org/mailman/listinfo/plone-product-developers
>



-- 
Au revoir, et tous mes voeux pour un avenir plein de succès et de bonheur ––

Malthe Borch
mborch at gmail.com


More information about the Product-Developers mailing list