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