[Zope3-Users] Re: Compound Form Elements
James Allwyn
jamesallwyn at gmail.com
Thu Oct 6 04:29:38 EDT 2005
On 04/10/05, James Allwyn <jamesallwyn at gmail.com> wrote:
> Hello,
>
> I wish my users to be able to register various contact details. For
> each, I would record the type (e.g. email, landline tel, mobile tel,
> fax...), the value (e.g. test at email.com) and a True/False value on
> whether it is to be visible on the site.
Thinking further about this, it seems to me that the natural data
structure would be dicts within a list. For example, if were doing it
in plain python it might go something like this:
>>> contacts = []
>>> contacts
[]
>>> contact1 = {"show":True, "type":"mobile tel", "value": "07123 456 789"}
>>> contact2 = {"show":False, "type":"email", "value": "email at test.com"}
>>> contact1['type']
'mobile tel'
>>> contact2['type']
'email'
>>> contacts.append(contact1)
>>> contacts.append(contact2)
>>> contacts
[{'type': 'mobile tel', 'value': '07123 456 789', 'show': True}, {'type': 'email
', 'value': 'email at test.com', 'show': False}]
>>> len(contacts)
2
>>>
I've tried to implement this zopeishly, and the stumbling block I've
hit seems to be specifying the key and value_type pairs in the dict.
So, for example:
>>> from zope.interface import Interface
>>> from zope.schema import List, Dict, Bool, TextLine
>>> class IUser(Interface):
... contacts = List(
... title=u"Contact Details",
... value_type=Dict(
... title=u"dictionary",
... value_type=Bool(title=u"show")
... value_type=TextLine(title=u"value")
... value_type=TextLine(title=u"type")
... )
... )
This barfs when it hits the second value_type in the dict. Look at the
zope.schema sources it seems I can only specify one value_type and one
key_type. What I want to do is specify three pairs of keys and
value_types - note, specifying the actual keys, not just their types.
Is this possible? Or am I barking up the wrong tree!?
Any hints gratefully received.
Thanks,
James
> This seems to me to add up to an amalgamation of one each of Choice,
> TextLine and Bool Schema elements. Should I build up a custom Schema
> item that combines these three things, or would anyone recommend an
> alternative route? It would be nice if I could combine this with a bit
> of checking for validity of the value (obviously based on the type
> selected).
>
> From a visual perspective, Schema based forms seem to stack each
> schema element up on a new line. To make better use of screen 'real
> estate' (and to logically group) I think it would be better if my
> amalgamation appeared on one line. Does this have any baring on how I
> should approach the issue?
>
> Alternatively, I'd be open to any suggestions on completely different
> ways of handling this - the 'custom schema element' way does have the
> problem that if I wanted to allow up to, say, six contact details to
> be provided I would have to put six sets of three control elements on
> screen, which would be wasteful for users who only want to specify one
> contact detail.
>
> Thanks,
> James
>
More information about the Zope3-users
mailing list