From 7709074d7ceaf0ea981073be1ff507a5355661cb Mon Sep 17 00:00:00 2001 From: mdipierro Date: Thu, 27 Sep 2012 15:12:36 -0500 Subject: [PATCH] fixed field_parent references broken in 2.0.x, thanks Marin --- VERSION | 2 +- gluon/sqlhtml.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/VERSION b/VERSION index 8f6292fd..192fff3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.0.9 (2012-09-27 14:43:52) stable +Version 2.0.9 (2012-09-27 15:12:31) stable diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index eedefec4..f560b912 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -1142,16 +1142,16 @@ class SQLFORM(FORM): if defaults and len(args) - len(defaults) == 4 or len(args) == 4: table = TABLE() for id,a,b,c in xfields: - raw_b = self.field_parent[id] = b - newrows = formstyle(id,a,raw_b,c) + newrows = formstyle(id,a,b,c) + self.field_parent[id] = b.parent if type(newrows).__name__ != "tuple": newrows = [newrows] for newrow in newrows: table.append(newrow) else: - for id,a,b,c in xfields: - self.field_parent[id] = b table = formstyle(self, xfields) + for id,a,b,c in xfields: + self.field_parent[id] = b.parent else: raise RuntimeError, 'formstyle not supported' return table @@ -1284,14 +1284,15 @@ class SQLFORM(FORM): value = self.record[fieldname] else: value = self.table[fieldname].default - if field.type.startswith('list:') and \ - isinstance(value, str): + if field.type.startswith('list:') and isinstance(value, str): value = [value] row_id = '%s_%s%s' % (self.table, fieldname, SQLFORM.ID_ROW_SUFFIX) widget = field.widget(field, value) - self.field_parent[row_id].components = [ widget ] - self.field_parent[row_id]._traverse(False, hideerror) - self.custom.widget[ fieldname ] = widget + parent = self.field_parent[row_id] + if parent: + parent.components = [ widget ] + parent._traverse(False, hideerror) + self.custom.widget[fieldname] = widget self.accepted = ret return ret