From fa9ef1b76c60ad7777f62b855e680d01f0e2eed1 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Sun, 30 Nov 2014 11:38:29 +0100 Subject: [PATCH] [gen] Boolean field: bugfix (defaut layouts). --- fields/__init__.py | 9 +++++++++ fields/boolean.py | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fields/__init__.py b/fields/__init__.py index a10ccc8..2dab81b 100644 --- a/fields/__init__.py +++ b/fields/__init__.py @@ -467,6 +467,15 @@ class Field: self.hasHelp = self.hasLayoutElement('h', layouts) return layouts + @staticmethod + def copyLayouts(layouts): + '''Create a deep copy of p_layouts.''' + res = {} + for k, v in layouts.iteritems(): + if isinstance(v, Table): res[k] = Table(other=v) + else: res[k] = v + return res + def hasLayoutElement(self, element, layouts): '''This method returns True if the given layout p_element can be found at least once among the various p_layouts defined for this field.''' diff --git a/fields/boolean.py b/fields/boolean.py index 043d30b..e6acf64 100644 --- a/fields/boolean.py +++ b/fields/boolean.py @@ -27,7 +27,7 @@ class Boolean(Field): trueFalse = {True: 'true', False: 'false'} # Default layout (render = "checkbox") ("b" stands for "base"). - bLayouts = {'view': 'lf', 'edit': Table('f;lrv;=', width=None), + bLayouts = {'view': 'lf', 'edit': Table('f;lrv;-', width=None), 'search': 'l-f'} # Layout including a description. dLayouts = {'view': 'lf', 'edit': Table('flrv;=d', width=None)} @@ -97,7 +97,9 @@ class Boolean(Field): self.pythonType = bool def getDefaultLayouts(self): - return (self.render == 'radios') and self.rLayouts or self.bLayouts + cp = Field.copyLayouts + if self.render == 'radios': return cp(Boolean.rLayouts) + return cp(Boolean.bLayouts) def getValue(self, obj): '''Never returns "None". Returns always "True" or "False", even if