Re: [Zope3-Users] Nested lists- iteration over non-sequence

2006-11-11 Thread Tom Dossis
Daniel M wrote:
 Hi Kevin,
 Thanks for the help! 
 
 I've studied your example at
 http://zope3demos.googlecode.com/svn/tags/zope3demos-200610-21/otherdemos/objectsofobjects2/
  
 but I don't see how I could extend this example into a List of List.
 
 Suppose I want to change your IPerson to include a list, such as:
 
 class IPerson(interface.Interface):
 first = schema.TextLine(title=ufirstname)
 last = schema.TextLine(title=ulastname)
 names = schema.List(title=u'Names',
   value_type=schema.TextLine(title=unames),
   required=False)
 
 I can't figure out how to create to modify the widgets so that
 AddressBook will display correctly... I keep getting the Iteration over
 non sequence exception.


Hi Daniel,
Taking the error at face-value, the following may (or not) help:

 names = schema.List(title=u'Names',
   value_type=schema.TextLine(title=unames),
   required=False,
   default=[])

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Nested lists- iteration over non-sequence

2006-10-21 Thread Alek Kowalczyk

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=unames,
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!
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Nested lists- iteration over non-sequence

2006-10-21 Thread ksmith93940-dev
Hi, Yes, one solution is custom widgets. Although I don't have a List of List 
example, I do have a List of Object example. It uses formlib, 
CustomWidgetFactory, ListSequenceWidget and ObjectWidget

http://zope3demos.googlecode.com/svn/tags/zope3demos-200610-21/otherdemos/objectsofobjects2/

Project at http://zope3demos.googlecode.com/


Kevin Smith

- Original Message 
From: Daniel M [EMAIL PROTECTED]
To: zope3-users@zope.org
Sent: Friday, October 20, 2006 2:47:36 PM
Subject: [Zope3-Users] Nested lists- iteration over non-sequence

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.

When I enter the view for Person (based on EditForm), it displays an
edit form as I would expect. However, when I try to add a PersonInfo to
the list via the interface, an exception is raised:

“TypeError: iteration over non-sequence” 

(The full traceback is over 6 pages long, so I won’t post it, but it
does mention “sequencewidget” many times).
 

I've tried some variations to narrow down the problem:

*If I change PersonInfo to hold just a string instead of a list, it
works!

*If I change Person to hold just a single PersonInfo instead of a list,
it works!

* Therefore, it seems like my Zope site is set up OK, but for some
reason Lists of objects with Lists raise an exception.
 
Am I missing something? Maybe I have to write some custom widget to get
around this? Is this possibly a known problem?

The code:

** People.py *

class IPersonInfo(interface.Interface):
names = schema.List(
title=unames,
unique=False,
value_type=schema.TextLine(title=u'name')
)


class IPerson(interface.Interface):
ID = schema.TextLine(
title=u'ID',
description=u'Persons ID code')

the_list = schema.List(
title=uPersonInfo list,
unique=False,
value_type=schema.Object(IPersonInfo))

class PersonInfo(persistent.Persistent):
interface.implements(IPersonInfo)
def __init__(self):
self.names = persistent.list.PersistentList()

def PersonInfoWidget(context,obj,request):
return ObjectWidget(context, request, PersonInfo)

class Person(persistent.Persistent):
interface.implements(IPerson)
ID = 1-2-3   
def __init__(self):
self.the_list = persistent.list.PersistentList()


class AutoEditView(form.EditForm):
form_fields = form.Fields(IPerson)

class PersonInfoView(form.EditForm):
form_fields = form.Fields(IPersonInfo)

** end People.py *

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!
-- 
  Daniel M
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Send your email first class

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users



___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


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

2006-10-20 Thread Daniel M
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.

When I enter the view for Person (based on EditForm), it displays an
edit form as I would expect. However, when I try to add a PersonInfo to
the list via the interface, an exception is raised:

“TypeError: iteration over non-sequence” 

(The full traceback is over 6 pages long, so I won’t post it, but it
does mention “sequencewidget” many times).
 

I've tried some variations to narrow down the problem:

*If I change PersonInfo to hold just a string instead of a list, it
works!

*If I change Person to hold just a single PersonInfo instead of a list,
it works!

* Therefore, it seems like my Zope site is set up OK, but for some
reason Lists of objects with Lists raise an exception.
 
Am I missing something? Maybe I have to write some custom widget to get
around this? Is this possibly a known problem?

The code:

** People.py *

class IPersonInfo(interface.Interface):
names = schema.List(
title=unames,
unique=False,
value_type=schema.TextLine(title=u'name')
)


class IPerson(interface.Interface):
ID = schema.TextLine(
title=u'ID',
description=u'Persons ID code')

the_list = schema.List(
title=uPersonInfo list,
unique=False,
value_type=schema.Object(IPersonInfo))

class PersonInfo(persistent.Persistent):
interface.implements(IPersonInfo)
def __init__(self):
self.names = persistent.list.PersistentList()

def PersonInfoWidget(context,obj,request):
return ObjectWidget(context, request, PersonInfo)

class Person(persistent.Persistent):
interface.implements(IPerson)
ID = 1-2-3   
def __init__(self):
self.the_list = persistent.list.PersistentList()


class AutoEditView(form.EditForm):
form_fields = form.Fields(IPerson)

class PersonInfoView(form.EditForm):
form_fields = form.Fields(IPersonInfo)

** end People.py *

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!
-- 
  Daniel M
  [EMAIL PROTECTED]

-- 
http://www.fastmail.fm - Send your email first class

___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users