我希望为我的基于Dexterity的自定义内容类型的属性('sector')启用一个名为Sectors的特殊索引。
I wish to enable a special index, called Sectors, for a attribute ('sectors') of my Dexterity based custom content-type.
在我的架构中,在 types / mycontent.py 里面我有:
In my schema, inside types/mycontent.py I have:
class IMyContent(form.Schema): """ My Content """ sectors = schema.Set( title=_(u"Sectors"), description=_(u"Select some sectors"), value_type=schema.Choice(vocabulary=vocs.sectors), required=True, ) (...)然后我以这种方式定义索引,在 indexers.py 中
I then define the index in this way, inside indexers.py
from plone.indexer.decorator import indexer from zr.content.types.mycontent import IMyContent @indexer(IMyContent) def Sectors(obj): """Indexer for Sectors attribute. """ d = getattr(obj, "sectors", u"") return d if d else None最后在根包中 configure.zcml :
<adapter name="Sectors" factory=".indexers.Sectors"/>然而,它似乎不起作用。即使重新安装产品后,我也看不到portal_catalog和目录脑对象中的索引似乎也没有。
However, it does not seem to work. Even after reinstalling the product, I don't see the index in portal_catalog and catalog brain object do not seem to have it either.
我做错了什么?
推荐答案您没有定义目录索引。这只会使索引器可用。您需要GenericSetup配置文件中的catalog.xml:
You aren't defining the catalogue index. This will just make the indexer available to be added. You require a catalog.xml in your GenericSetup profile with:
<?xml version="1.0"?> <object name="portal_catalog" meta_type="Plone Catalog Tool"> <index name="Sectors" meta_type="KeywordIndex"> <indexed_attr value="Sectors"/> </index> </object>更多推荐
plone.indexer和Dexterity的问题
发布评论