On further thought it appears to me that defining the tables in a 
controller function as shown in my post above would mean
that they are not available for access to other functions. And, hence, the 
above may not be a good idea.

I would really appreciate an example of how I create tables based on user 
input that are also available to other controller functions.

Thanks.

On Sunday, September 30, 2012 5:31:50 PM UTC-4, curiouslearn wrote:
>
> Hello,
>
> This is a question about recommended practice for doing the following:
>
> I want to create a web interface for creating a setup for new games. For 
> example, the web interface will let me specify 
> name of the game, number of teams etc. Based on this information I want to 
> create new database tables for the game.
> Should the table definitions be given in a controller function, such as in 
> the example below? Is that the recommended way
> to do this, or is there another way that you would recommend.
>
> Thank you.
>
> ***Controller function for creating tables***
>
> def createtables():
>     if request.post_vars:
>         experimentname = request.post_vars.experimentname
>         numteams = int(float(request.post_vars.numteams))
>         teams_tablename = "{0}_teams".format(experimentname)
>         offers_tablename = "{0}_offers".format(experimentname)
>         ardecisions_tablename = "{0}_ardecisions".format(experimentname)
>         migrate_teamstablename = "{0}.table".format(teams_tablename)
>         migrate_offerstablename = "{0}.table".format(offers_tablename)
>         migrate_ardecisionstablename = "{0}.table".format(
> ardecisions_tablename)
>         db.define_table(teams_tablename, 
>                 Field('teamname', 'string', length=40, required=True,
>                       unique=True, notnull=True),
>                 Field('passwd', 'password'),
>                 Field('role', 'string', length=20, required=True,
>                       default='NA'),
>                 format = '%(teamname)s', migrate=migrate_teamstablename)
>         # Table showing the ask amount of the first mover
>         referencestring = 'reference {0}'.format(teams_tablename)
>         db.define_table(offers_tablename,
>                         Field('round', 'integer'),
>                         Field('askamount', 'integer'),
>                         Field('payoff', 'integer'),
>                         Field('teamname_id', referencestring),
>                         migrate = migrate_offerstablename)
>
>
>         # Table accept-reject decisions
>         db.define_table(ardecisions_tablename,
>                         Field('round', 'integer'),
>                         Field('acceptorreject', 'string', length=2),
>                         Field('payoff', 'integer'),
>                         Field('teamname_id', referencestring),
>                         Field('offerer_id', referencestring),
>                         migrate = migrate_ardecisionstablename)
>
>
>         teamnames = maketeamnames(numteams)
>         for tname in teamnames:
>             db[teams_tablename].update_or_insert(teamname=tname)
>         db.experimentlist.insert(experimentname=experimentname)
>     return dict()
>
>
>
>

-- 



Reply via email to