From e87a2bf0d53dec07862b97bfe174e58f0f288e8c Mon Sep 17 00:00:00 2001 From: mdipierro Date: Wed, 3 Apr 2013 14:46:13 -0500 Subject: [PATCH] populate(...contents), thanks Vinicius --- VERSION | 2 +- gluon/contrib/populate.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 47b5cd7e..ea454a44 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.5-stable+timestamp.2013.04.03.11.31.36 +Version 2.4.5-stable+timestamp.2013.04.03.14.45.24 diff --git a/gluon/contrib/populate.py b/gluon/contrib/populate.py index c02b6ca1..36086a59 100644 --- a/gluon/contrib/populate.py +++ b/gluon/contrib/populate.py @@ -75,7 +75,7 @@ def da_du_ma(n=4): [random.randint(0, 11)] for i in range(n)]) -def populate(table, n, default=True, compute=False): +def populate(table, n, default=True, compute=False, contents={}): ell = Learner() #ell.learn(open('20417.txt','r').read()) #ell.save('frequencies.pickle') @@ -84,7 +84,14 @@ def populate(table, n, default=True, compute=False): ids = {} for i in range(n): record = {} + + record.update(contents) # load user supplied contents. + for fieldname in table.fields: + + if record.get(fieldname) is not None: + continue # if user supplied it, let it be. + field = table[fieldname] if not isinstance(field.type, (str, unicode)): continue