Check if context is ignored when getting field value
authorThierry Florac <thierry.florac@onf.fr>
Wed, 18 Jul 2018 15:48:37 +0200
changeset 132 772f71ac0698
parent 131 16241f36971b
child 133 a8ac89790088
Check if context is ignored when getting field value
src/pyams_form/group.py
--- a/src/pyams_form/group.py	Tue Jul 17 18:02:48 2018 +0200
+++ b/src/pyams_form/group.py	Wed Jul 18 15:48:37 2018 +0200
@@ -85,9 +85,12 @@
     def visible(self):
         if self.checkbox_switch:
             widget = self.checkbox_widget
-            context = widget.context
-            name = widget.field.getName()
-            value = getattr(widget.field.interface(context), name, None)
+            if self.form.ignoreContext:
+                value = widget.field.default
+            else:
+                context = widget.context
+                name = widget.field.getName()
+                value = getattr(widget.field.interface(context), name, None)
             return bool(value)
         else:
             if self.display_mode == 'never':
@@ -98,9 +101,12 @@
                 for widget in self.widgets:
                     if not widget.ignoreContext:
                         field = widget.field
-                        context = widget.context
-                        name = field.getName()
-                        value = getattr(field.interface(context), name, None)
+                        if self.form.ignoreContext:
+                            value = field.default
+                        else:
+                            context = widget.context
+                            name = field.getName()
+                            value = getattr(field.interface(context), name, None)
                         if value and (value != field.default):
                             if II18nField.providedBy(field):
                                 for i18n_value in value.values():