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

Andreas Jung lists at zopyx.com
Fri Nov 16 08:03:51 UTC 2012


-----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-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lists.vcf
Type: text/x-vcard
Size: 353 bytes
Desc: not available
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20121116/17d9296f/attachment.vcf>


More information about the Product-Developers mailing list