diff --git a/VERSION b/VERSION index 0c966fba..c118fb34 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-07-11 18:16:55) dev +Version 2.00.0 (2012-07-11 18:21:38) dev diff --git a/gluon/contrib/populate.py b/gluon/contrib/populate.py index 22a18b33..7e93c3f0 100644 --- a/gluon/contrib/populate.py +++ b/gluon/contrib/populate.py @@ -103,11 +103,8 @@ def populate(table, n, default=True, compute=False): elif field.type=='list:integer' and hasattr(field.requires,'options'): options=field.requires.options(zero=False) if len(options) > 0: - vals = [] - for i in range(0, random.randint(0,len(options)-1)/2): - vals.append(options[random.randint(0,len(options)-1)][0]) - record[fieldname] = vals - elif field.type =='integer': + record[fieldname] = [item[0] for item in random.sample(options, random.randint(0,len(options)-1)/2)] + elif field.type == 'integer': try: record[fieldname] = random.randint(field.requires.minimum,field.requires.maximum-1) except: @@ -143,19 +140,13 @@ def populate(table, n, default=True, compute=False): ids[tablename] = [x.id for x in table._db(table._db[field.type[15:]].id>0).select()] n = len(ids[tablename]) if n: - vals = [] - for i in range(0, random.randint(0,n-1)/2): - vals.append(ids[tablename][random.randint(0,n-1)]) - record[fieldname] = vals + record[fieldname] = [item[0] for item in random.sample(ids[tablename], random.randint(0,n-1)/2)] else: record[fieldname] = 0 elif field.type=='list:string' and hasattr(field.requires,'options'): options=field.requires.options(zero=False) if len(options) > 0: - vals = [] - for i in range(0, random.randint(0,len(options)-1)/2): - vals.append(options[random.randint(0,len(options)-1)][0]) - record[fieldname] = vals + record[fieldname] = [item[0] for item in random.sample(options, random.randint(0,len(options)-1)/2)] elif field.type=='string' and hasattr(field.requires,'options'): options=field.requires.options(zero=False) record[fieldname] = options[random.randint(0,len(options)-1)][0]