Corrected JSON-RPC filter so that empty objects are correctly returned
authorThierry Florac <tflorac@ulthar.net>
Tue, 30 Oct 2018 13:57:05 +0100
changeset 72 17accf89d8a8
parent 71 b8b27829493f
child 73 1a77f19cd7de
child 75 4740e424ef1a
Corrected JSON-RPC filter so that empty objects are correctly returned
src/pyams_sequence/rpc/json/__init__.py
--- a/src/pyams_sequence/rpc/json/__init__.py	Tue Sep 25 11:34:06 2018 +0200
+++ b/src/pyams_sequence/rpc/json/__init__.py	Tue Oct 30 13:57:05 2018 +0100
@@ -12,22 +12,17 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
+from hypatia.catalog import CatalogQuery
+from hypatia.interfaces import ICatalog
+from hypatia.query import Contains, Eq
+from pyramid_rpc.jsonrpc import jsonrpc_method
 
-# import interfaces
-from hypatia.interfaces import ICatalog
+from pyams_catalog.query import CatalogResultSet
 from pyams_i18n.interfaces import INegotiator
 from pyams_sequence.interfaces import ISequentialIntIds
-
-# import packages
-from hypatia.catalog import CatalogQuery
-from hypatia.query import Eq, Contains
-from pyams_catalog.query import CatalogResultSet
 from pyams_sequence.reference import get_last_version, get_sequence_dict
 from pyams_utils.list import unique
 from pyams_utils.registry import get_utility
-from pyramid_rpc.jsonrpc import jsonrpc_method
 
 
 @jsonrpc_method(endpoint='sequence')
@@ -49,12 +44,12 @@
             if index_name in catalog:
                 index = catalog[index_name]
                 if index.check_query(query):
-                    query_params |= Contains(index, ' and '.join((w+'*' for w in query.split())))
+                    query_params |= Contains(index, ' and '.join((w + '*' for w in query.split())))
         params = query_params
     if content_type:
         params &= Eq(catalog['content_type'], content_type)
     return sorted([get_sequence_dict(result)
-                   for result in unique(filter(None,
+                   for result in unique(filter(lambda x: x is not None,
                                                map(get_last_version,
                                                    CatalogResultSet(CatalogQuery(catalog).query(params)))))],
                   key=lambda x: x['text'])