I used to be able to create dynamic vocabularies by pulling items from portal_catalog without any issues in Plone 4 but for the life of me, I cannot get it to work in Plone 5. I want a search term in collections to include NC Counties which has 100 items. However, when I try to list the values of this field as a drop down menu by using vocabularies, the entire search term section will disappear. Without the vocabulary section, hence the drop down menu, the search term section reappears with the NC County as a search term. One just has to type in the county manually instead of being able to choose from a list. This is what I have done for the Dexterity field called nc_county
:
Plone 5.1.0.1 (5110)
CMF 2.2.12
Zope 2.13.26
Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
PIL 3.4.2 (Pillow)
ncdhhscontenttype.ncssinfo/src/ncdhhscontenttype/ncssinfo/vocabulary.py:
from Products.CMFCore.utils import getToolByName from zope.interface import implementer from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleTerm from zope.schema.vocabulary import SimpleVocabulary def vocab_from_catalog_index(index_name): @implementer(IVocabularyFactory) class VocabFactory(object): def __call__(self, context): catalog = getToolByName(context, 'portal_catalog') terms = [] for value in catalog.Indexes[index_name].uniqueValues(): if value is None: continue encoded_value = value.encode('utf8') terms.append(SimpleTerm( value=encoded_value, token=value.encode('raw_unicode_escape'), title=value, )) return SimpleVocabulary(terms) return VocabFactory nc_county_vocab = vocab_from_catalog_index('nc_county')
ncdhhscontenttype.ncssinfo/src/ncdhhscontenttype/ncssinfo/configure.zcmlconfigure.zcml:
<utility name="ncdhhscontenttype.ncssinfo.vocabulary.nc_county" factory="ncdhhscontenttype.ncssinfo.vocabulary.nc_county_vocab" />
ncdhhscontenttype.ncssinfo/src/ncdhhscontenttype/ncssinfo/profiles/default/registry.xml
<records interface="plone.app.querystring.interfaces.IQueryField" prefix="plone.app.querystring.field.nc_county"> <value key="title">NC County</value> <value key="description">A custom NC County index</value> <value key="enabled">True</value> <value key="sortable">False</value> <value key="operations"> <element>plone.app.querystring.operation.string.is</element> </value> <value key="vocabulary">ncdhhscontenttype.ncssinfo.vocabulary.nc_county</value> <value key="group">Metadata</value> </records>
The error seems to be coming from my vocabulary.py file:
Traceback (innermost last): Module ZPublisher.Publish, line 138, in publish Module ZPublisher.mapply, line 77, in mapply Module ZPublisher.Publish, line 48, in call_object Module plone.app.content.browser.query, line 13, in __call__ Module plone.app.querystring.registryreader, line 136, in __call__ Module plone.app.querystring.registryreader, line 87, in getVocabularyValues Module ncdhhscontenttype.ncssinfo.vocabulary, line 17, in __call__ AttributeError: 'set' object has no attribute 'encode'
Line 17: encoded_value = value.encode('utf8')
Any advice or help would be most appreciated. Thank you so much.