From 5dd452554e2920e61b70f8381e2dd5ccf834d764 Mon Sep 17 00:00:00 2001 From: Tim Richardson Date: Fri, 21 Jun 2013 03:21:13 +1000 Subject: [PATCH 1/4] allow compute fields to depend on compute fields defined earlier --- gluon/dal.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gluon/dal.py b/gluon/dal.py index 7d0190aa..194413a4 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -8542,6 +8542,8 @@ class Table(object): # try compute it try: new_fields[name] = (ofield,ofield.compute(row)) + __,fields[name] = new_fields[name] #the value is the second element of the tuple + row = Row(fields) #allow later compute fields to refer to this value except (KeyError, AttributeError): # error sinlently unless field is required! if ofield.required: From 4c2fba134d6cbd75be6063ee69dad714055722ae Mon Sep 17 00:00:00 2001 From: Tim Richardson Date: Fri, 21 Jun 2013 03:34:51 +1000 Subject: [PATCH 2/4] fixed a typo in error message --- gluon/dal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluon/dal.py b/gluon/dal.py index 194413a4..3312c724 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -8547,7 +8547,7 @@ class Table(object): except (KeyError, AttributeError): # error sinlently unless field is required! if ofield.required: - raise SyntaxError('unable to comput field: %s' % name) + raise SyntaxError('unable to compute field: %s' % name) return new_fields.values() def _attempt_upload(self, fields): From 545e304a73575ee86be497d6788e570573f253a3 Mon Sep 17 00:00:00 2001 From: Tim Richardson Date: Fri, 21 Jun 2013 09:52:31 +1000 Subject: [PATCH 3/4] minor typo (but hopefully will start travis on my repository ) --- gluon/dal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluon/dal.py b/gluon/dal.py index 3312c724..f9799871 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -8545,7 +8545,7 @@ class Table(object): __,fields[name] = new_fields[name] #the value is the second element of the tuple row = Row(fields) #allow later compute fields to refer to this value except (KeyError, AttributeError): - # error sinlently unless field is required! + # error silently unless field is required! if ofield.required: raise SyntaxError('unable to compute field: %s' % name) return new_fields.values() From c3be2e5f8a84f3d54a27ceb249442d194260212b Mon Sep 17 00:00:00 2001 From: Tim Richardson Date: Fri, 21 Jun 2013 11:20:17 +1000 Subject: [PATCH 4/4] test case for the changes allowing a compute field to refer to an earlier defined compute field --- gluon/tests/test_dal.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gluon/tests/test_dal.py b/gluon/tests/test_dal.py index f4423b54..ab444958 100644 --- a/gluon/tests/test_dal.py +++ b/gluon/tests/test_dal.py @@ -599,6 +599,19 @@ class TestComputedFields(unittest.TestCase): self.assertEqual(db.tt[id].cc,'zx') db.tt.drop() db.commit() + + # test checking that a compute field can refer to earlier-defined computed fields + db.define_table('tt', + Field('aa'), + Field('bb',default='x'), + Field('cc',compute=lambda r: r.aa+r.bb), + Field('dd',compute=lambda r: r.bb + r.cc)) + db.commit() + id = db.tt.insert(aa="z") + self.assertEqual(db.tt[id].dd,'xzx') + db.tt.drop() + db.commit() + class TestCommonFilters(unittest.TestCase):