[Zope3-Users] Re: Compound Form Elements

James Allwyn jamesallwyn at gmail.com
Fri Oct 21 14:16:11 EDT 2005


Hello List,

Thanks to a pointer given to me by Duncan off list, I've looked at a
fixed version of the poll demo, posted by Christian Lueck to this list
earlier in the year (Mon, 29 Aug 2005).

This works a treat, and following the poll as an example I've been
able to create something similar:

class IContactDatum(Interface):
    """A Contact Detail.

    For each contact detail we record whether it is shown on the site,
and what type of
    contact detail it is, as well as the contact itself.
    """

    show = Bool(title = u"Show on Site?")

    type = TextLine(
        title = u'Type of Contact Detail',
        min_length=1)

    value = TextLine(
        title = u'Contact Detail',
        min_length=1)


class IContactData(Interface):
    """The Contact Data Interface"""

    contact_data = Tuple(
        title = u'Contact Details',
        value_type = Object(
            schema=IContactDatum,
            title=u'Contact Datum'))

Following Christian's tweaks to the browser.py file (creating a
CustomSequenceWidget), I've got this working well in isolation - I can
add a ContactData object on its own no problem.

However, I've hit a brick wall about how to use the ContactData item
as a form element within another schema (say, IPerson). I've tried to
access it with variations upon:

    contact_data = ContactData(
        title = u'Contact Details',
        description = u'Contact Details',
        required=False)

and:

    contact_details = Object(
        title = u"Contact Details",
        required = False,
        schema=IContactData)

I can generate the behaviour I want by using the ContactDatum items in
the IPerson definition:

    contact_data = Tuple(
        title = u'Contact Details',
        value_type = Object(
            schema=IContactDatum,
            title=u'Contact Datum'))

and invoking the browser class for the add view in the configure.zcml
for the User:

class=".contactdata.browser.ContactDataAddView"

In effect, this method doesn't use ContactData at all, it replicates
its functionality out of a Tuple of ContactDatum objects in the
IPerson itself. But what I want to do is be able to put a ContactData
element into IPerson and have it 'just work', in the same way I can
for, say, TextLine, or Bool.

I would appreciate any suggestions on what I need to do to my
ContactData package to make this happen.

Thanks in advance,
James


More information about the Zope3-users mailing list