Added custom "IKeyValue" adapter for catalog
authorThierry Florac <thierry.florac@onf.fr>
Wed, 12 Jul 2017 11:39:41 +0200
changeset 23 1f82b278bacc
parent 22 8c121a145dbe
child 24 651c3646cab3
Added custom "IKeyValue" adapter for catalog
src/pyams_catalog/utils.py
--- a/src/pyams_catalog/utils.py	Wed Jul 12 11:38:51 2017 +0200
+++ b/src/pyams_catalog/utils.py	Wed Jul 12 11:39:41 2017 +0200
@@ -19,13 +19,21 @@
 
 # import interfaces
 from hypatia.interfaces import ICatalog
+from pyams_utils.interfaces import IKeyValue
 from zope.intid.interfaces import IIntIds
 
 # import packages
+from pyams_utils.adapter import adapter_config
 from pyams_utils.registry import query_utility
 from zope.keyreference.interfaces import NotYet
 
 
+@adapter_config(context=ICatalog, provides=IKeyValue)
+def catalog_key_adapter(obj):
+    """Catalog key value adapter"""
+    return str(frozenset(obj))
+
+
 def index_object(obj, catalog, ignore_notyet=False):
     """Index given object into catalog"""
     logger.debug("Indexing object {0!r}".format(obj))