From 7b0cf5bc1264d6dd03536e669bcc811d50251777 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Wed, 10 Apr 2013 22:14:59 -0500 Subject: [PATCH] fixed auth.settings.wiki and make populate generator --- VERSION | 2 +- applications/welcome/models/menu.py | 11 +++++++ gluon/contrib/populate.py | 47 ++++++++++++++++++++++++----- gluon/tools.py | 1 + 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index 15f5befa..b39c12c1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.6-stable+timestamp.2013.04.10.12.36.12 +Version 2.4.6-stable+timestamp.2013.04.10.22.14.20 diff --git a/applications/welcome/models/menu.py b/applications/welcome/models/menu.py index 1178d928..a9930ed8 100644 --- a/applications/welcome/models/menu.py +++ b/applications/welcome/models/menu.py @@ -136,3 +136,14 @@ def _(): ] )] if DEVELOPMENT_MENU: _() + + +######################################################################### +## This adds the wiki menu to any action if specified in wiki settings. +######################################################################### + +if "auth" in locals(): + if auth.settings.wiki.controller and auth.settings.wiki.function: + auth.wiki(controller=auth.settings.wiki.controller, + function=auth.settings.wiki.function) + diff --git a/gluon/contrib/populate.py b/gluon/contrib/populate.py index 36086a59..186d7da9 100644 --- a/gluon/contrib/populate.py +++ b/gluon/contrib/populate.py @@ -75,21 +75,53 @@ def da_du_ma(n=4): [random.randint(0, 11)] for i in range(n)]) -def populate(table, n, default=True, compute=False, contents={}): +def populate(table, n=None, default=True, compute=False, contents={}): + """Populate table with n records. + + if n is None, it does not populate the database but returns a generator + if default=True use default values to fields. + if compute=False doesn't load values into computed fields. + if contents has data, use these values to populate related fields. + + can be used in two ways: + + >>> populate(db.tablename, n=100) + + or + + >>> for k,row in enumerate(populate(db.tablename)): print row + """ + + generator = populate_generator(table, default=default, + compute=compute, contents=contents) + if n is not None: + for k,record in enumerate(generator): + if k>=n: break + table.insert(**record) + table._db.commit() + + return generator + +def populate_generator(table, default=True, compute=False, contents={}): + """Populate table with n records. + + if default=True use default values to fields. + if compute=False doesn't load values into computed fields. + if contents has data, use these values to populate related fields. + """ + ell = Learner() #ell.learn(open('20417.txt','r').read()) #ell.save('frequencies.pickle') #ell.load('frequencies.pickle') ell.loadd(IUP) ids = {} - for i in range(n): - record = {} - record.update(contents) # load user supplied contents. + while True: + record = contents.copy() # load user supplied contents. for fieldname in table.fields: - - if record.get(fieldname) is not None: + if fieldname in record: continue # if user supplied it, let it be. field = table[fieldname] @@ -204,8 +236,7 @@ def populate(table, n, default=True, compute=False, contents={}): elif field.type == 'string': z = ell.generate(10, prefix=False) record[fieldname] = z[:field.length].replace('\n', ' ') - table.insert(**record) - table._db.commit() + yield record if __name__ == '__main__': ell = Learner() diff --git a/gluon/tools.py b/gluon/tools.py index b0383d26..5bfb4616 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -892,6 +892,7 @@ class Auth(object): username_case_sensitive=True, update_fields = ['email'], ondelete="CASCADE", + wiki = Settings(), ) # ## these are messages that can be customized default_messages = dict(