[Grok-dev] Adding indexes with the same field names

Leonardo Rochael Almeida leorochael at gmail.com
Sun Jul 29 14:26:20 EDT 2007

There might be other, more straightforward, options, but one that
might work (I didn't test it), is to have an interface like this:

  class IHaveATitle(interface.Interface):
      title = schema.TextLine(title=u"Title", required=True)
      # no more fields after this

And then make IBook and IArticle not implement the "title" schema
attribute directly. Then you can have Book (resp. Article) either
implement both IHaveATitle and IBook (resp. IArticle) or have IBook
and IArticle inherit from IHaveATitle (which is simpler).

In either case, you wouldn't have *_title attributes in BookIndexes
and ArticleIndexes, but would have an TitleIndex class instead with a
"grok.context(IHaveATitle)" declaration.

You could have BookIndexes and ArticleIndexes for the other Book and
Article fields if necessary, of course.

Cheers, Leo

On 7/29/07, Dirceu Pereira Tiegs <dirceutiegs at gmail.com> wrote:
> Hello guys,
> I have two classes implementing these two interfaces:
> class IBook(interface.Interface):
>      title = schema.TextLine(title=u"Title", required=True)
>      # more attributes here
> class IArticle(interface.Interface):
>      title = schema.TextLine(title=u"Title", required=True)
>      # more attributes here
> And these two indexes:
> class BookIndexes(grok.Indexes):
>      grok.site(BookShelf)
>      grok.context(Book)
>      book_title = index.Text('title') # should use title of IBook
> class ArticleIndexes(grok.Indexes):
>      grok.site(BookShelf)
>      grok.context(Article)
>      article_title = index.Text('title') # should use title of IArticle
> Well, when I test the application I get the following error:
> Exception raised:
>      Traceback (most recent call last):
>        File "/Users/dirceu/devel/buildout-eggs/tmpteHm0u/
> zope.testing-3.5.0-py2.4.egg/zope/testing/doctest.py", line 1356, in
> __run
>          if out is None:
>        File "<doctest bookshelf.ftests.xmlrpc[3]>", line 1, in ?
>          root['bookshelf'] = BookShelf()
>        [...]
>      TypeError: __init__() got multiple values for keyword argument
> 'field_name'
> My question is: how can I add these two indexes with the same
> attribute name?

More information about the Grok-dev mailing list