[Zope3-Users] Nested lists- "iteration over non-sequence"

Alek Kowalczyk thealx at poczta.onet.pl
Sat Oct 21 15:16:12 EDT 2006


Daniel M escribió:
> Hello, I'm new to Zope, and using Zope 3.3. I have managed to get a
> simple site running.
>
> I am having trouble getting the web interface to let me edit an object
> that contains a list, where the type of values in the list, is an
> interface that also holds a list.  I can’t get this “list inside a list”
> setup to work correctly.
>
> In my example, I have a Person object that contains a list of PersonInfo
> objects, where each PersonInfo contains a list of names.
>   
Do I understand correctly that for each person you want to store a list 
of  PersonInfos (say, his/her friends)? I suggest considering to make 
IPerson/Person a descendant of IContainer/BTreeContainer type and remove 
the_list attribute. Also maybe the same should be done for 
IPersonInfo/PersonInfo

If you want to stick to your current design - I think (but not sure) you 
should use CustomSequenceWidgetFactory (or CustomWidgetFactory?) to 
create a widget for your object.

I would change your code a bit, compare to your one (of course I did not 
check if it works, just a concept - no warranty ;) )
> class IPersonInfo(interface.Interface):
>     names = schema.List(
>         title=u"names",
>         unique=False,
>         value_type=schema.TextLine(title=u'name')
>     )
>
>
> class IPerson(IContainer):
>     ID = schema.TextLine(
>         title=u'ID',
>         description=u'Persons ID code')
>
>     contains(IPersonInfo)
>
> class PersonInfo(persistent.Persistent):    
>     interface.implements(IPersonInfo)
>     def __init__(self):
>         self.names = persistent.list.PersistentList()
>
>
> class Person(BTreeContainer):     # or OrderedContainer if you want to be able to preserve items' order
>     interface.implements(IPerson)
>     ID = "1-2-3"   
>     def __init__(self):
>         super(Person,self).__init__() #it's important to call BTreeContainer constructor
>
>
>
> configure.zcml doesn’t do anything unusual, it sets up the views to use
> my custom widgets and sets up the edit views and security. 
>
> Regards and thanks for your help!
>   
Regards!


More information about the Zope3-users mailing list