Handle null values in multi-references widget
authorThierry Florac <thierry.florac@onf.fr>
Fri, 09 Feb 2018 16:34:57 +0100
changeset 30 019da188c5a6
parent 29 84c17b46a32a
child 31 13548b20786f
Handle null values in multi-references widget
src/pyams_sequence/widget/__init__.py
--- a/src/pyams_sequence/widget/__init__.py	Thu Feb 08 15:03:18 2018 +0100
+++ b/src/pyams_sequence/widget/__init__.py	Fri Feb 09 16:34:57 2018 +0100
@@ -121,16 +121,17 @@
     def values_map(self):
         catalog = get_utility(ICatalog)
         sequence = get_utility(ISequentialIntIds)
+        results = {}
         values = self.value
-        if isinstance(values, str):
-            values = values.split(',')
-        params = Any(catalog['oid'], values)
-        results = {}
-        for item in map(get_last_version, CatalogResultSet(CatalogQuery(catalog).query(params))):
-            oid_info = ISequentialIdInfo(item)
-            results.update({oid_info.hex_oid: '{0} ({1})'.format(II18n(item).query_attribute('title',
-                                                                                             request=self.request),
-                                                                 sequence.get_short_oid(oid_info.oid))})
+        if values:
+            if isinstance(values, str):
+                values = values.split(',')
+            params = Any(catalog['oid'], values)
+            for item in map(get_last_version, CatalogResultSet(CatalogQuery(catalog).query(params))):
+                oid_info = ISequentialIdInfo(item)
+                results.update({oid_info.hex_oid: '{0} ({1})'.format(II18n(item).query_attribute('title',
+                                                                                                 request=self.request),
+                                                                     sequence.get_short_oid(oid_info.oid))})
         return json.dumps(results)