Hello Tom,
Thank you very much, your pointers helped me to solving it.
Tags was indexed with a TextIndex using my adapter FooTags which had
a function
to join the list:
def getSearchableList(self):
s = ' '.join(self.context.tags)
#if s == '':
#return None
return s
The part that is commented out was the cause of my error. Returning a
None when the
list is empty will of course cause an error of iteration over non-
sequence when indexing.
Btw, is there an already existing way to index a field with a list of
strings so you can do a
search on a particular element in the list? It's a little cumbrsome
writing an adapter for each
field that has a list of strings to join them as one string (if this
is even a good solution at all, I'm
not sure).
Regards
Steva
On Oct 22, 2007, at 11:20 PM, Tom Dossis wrote:
Hi Maken,
From the stack trace it looks like the problem is related to
cataloging your object.
From this point, there's a couple things to look at.
1. How are you cataloging IFoo? How did you set up the catalog?
2. Enter a break point or print statement in lexicon.py to see
what's happening in the method sourceToWordIds just after the call
to _text2list,
e.g. print repr(text), repr(last).
I'd be interested to see what these value's are. I can't see how
it's failing, but since it appears so, maybe there's a bug in
_text2list.
BTW, just to explain my original suggestion... When you use
EditForm, you have a Foo object, which means it's __init__ method
has been called and the tag attribute has been set to
PersistentList. However in the case of AddForm, there is no Foo
instance from which to bind the widgets to. In this case you may
need to explicitly say something about the tag field default value,
because AddForm will need to use this value.
-Tom
On 22/10/2007, at 9:14 PM, Maken Seteva wrote:
On Oct 18, 2007, at 10:54 PM, Tom Dossis wrote:
On 18/10/2007, at 11:58 PM, Maken Seteva wrote:
Hello,
I have a very strange error that I cannot understand. I get an
error for one of my attribute
only when it is named a certain name! It seems like there is an
old implementation of
it that is haunting in the background, how is this possible?
This cursed name is called tags. This attribute is a list of
TextLine. I get the error when I
don't add anything to the list in the adding view:
TypeError: iteration over non-sequence
However, if I rename the attribute to wehoo or really,
anything else, I don't get the TypeError and
I can add my content object successfully (with an empty list for
wehoo). Here's my component:
class IFoo(IContained):
#...
tags = List(
title=_(u'Tags'),
description=_(u'A list of keywords'),
max_length=10,
value_type=TextLine(title=_(u'Tag')),
unique=True
)
#...
class Foo(Persistent):
implements(IFoo)
__name__ = __parent__ = None
def __init__(self):
#...
self.tags = PersistentList()
#...
No custom widgets used for this field...
I tried deleting all .pyc-files and deleting all old Foo
objects, and the site i run for testing followed by
restarting the server. But adding new Foo objects still don't
work. (But renaming tags to anything else
and then trying again will succeed).
Any ideas?
Add: default=[] to your IFoo schema.
-Tom
Hi Tom,
I did just that and I still get the TypeError. It is kind of
confusing in how to allow an empty list
for a schema field. If required=True for the list, why doesn't it
complain when I don't add
anything to the list in the form? Btw, I don't want this field to
be required, but i just noticed
this oddity(?) when trying different settings.
This was the last setting for the field I used (and it failed):
tags = List(
title=_(u'Tags'),
description=_(u'A list of keywords'),
max_length=10,
required=False,
default=[],
value_type=TextLine(title=_(u'Tag')),
unique=True
)
I printed out the data dict in my AddForm's create function to
see what the value for tags was when no tags are added in the
form.. it is really an empty list..
Here's my full traceback I get after pressing Add button in my
adding view for Foo:
2007-10-22T12:31:13 ERROR SiteError http://localhost:8080/Site/
foos/+/mytest.addpage.Foo%3D
Traceback (most recent call last):
File /home/mset/local/Zope-3.3.1/lib/python/zope/publisher/
publish.py, line 133, in publish
result = publication.callObject(request, obj)
File /home/mset/local/Zope-3.3.1/lib/python/zope/app/
publication/zopepublication.py, line 161, in callObject
return mapply(ob, request.getPositionalArguments(), request)
File /home/mset/local/Zope-3.3.1/lib/python/zope/publisher/
publish.py, line 108, in mapply
return debug_call(obj, args)
-