Handle null value in principals widgets
authorThierry Florac <thierry.florac@onf.fr>
Thu, 02 Jun 2016 16:17:08 +0200
changeset 63 402858ec5ac9
parent 62 9f4dec677e75
child 64 59d37fc75008
Handle null value in principals widgets
src/pyams_security/widget/__init__.py
src/pyams_security/widget/templates/principals-set-input.pt
--- a/src/pyams_security/widget/__init__.py	Thu Jun 02 16:15:58 2016 +0200
+++ b/src/pyams_security/widget/__init__.py	Thu Jun 02 16:17:08 2016 +0200
@@ -28,7 +28,7 @@
 # import packages
 from pyams_form.widget import widgettemplate_config
 from pyams_utils.adapter import adapter_config
-from pyams_utils.registry import query_utility, get_all_utilities_registered_for, get_utilities_for
+from pyams_utils.registry import query_utility
 from z3c.form.browser.select import SelectWidget
 from z3c.form.browser.widget import HTMLInputWidget
 from z3c.form.converter import BaseDataConverter
@@ -254,7 +254,7 @@
     @property
     def values_map(self):
         result = {}
-        [result.update({value.id: value.title}) for value in self.value]
+        [result.update({value.id: value.title}) for value in self.value or ()]
         return json.dumps(result)
 
 
--- a/src/pyams_security/widget/templates/principals-set-input.pt	Thu Jun 02 16:15:58 2016 +0200
+++ b/src/pyams_security/widget/templates/principals-set-input.pt	Thu Jun 02 16:17:08 2016 +0200
@@ -19,7 +19,7 @@
 							class string:select2 ${view/klass};
 							style view/style;
 							title view/title;
-							value python:'|'.join((value.id for value in view.value));
+							value python:'|'.join((value.id for value in view.value or ()));
 							lang view/lang;
 							onclick view/onclick;
 							ondblclick view/ondblclick;