def make_table(table, fields):
    rawtable = table
    if table != 'auth_user':
        table = 't_' + table
    s = ''
    s += '\n' + '#' * 40 + '\n'
    s += "db.define_table('%s',\n" % table
    first_field = 'id'
    for field in fields:
        items = [x.lower() for x in field.split()]
        has = {}
        keys = []
        for key in ['notnull', 'unique', 'integer', 'double', 'boolean', 'float',
                    'boolean', 'date', 'time', 'datetime', 'text', 'wiki',
                    'html', 'file', 'upload', 'image', 'true',
                    'hidden', 'readonly', 'writeonly', 'multiple',
                    'notempty', 'required']:
            if key in items[1:]:
                keys.append(key)
                has[key] = True
        tables = session.app['tables']
        refs = [t for t in tables if t in items]
        items = items[:1] + [x for x in items[1:]
                             if not x in keys and not x in tables]
        barename = name = '_'.join(items)
        if table[:2] == 't_': name = 'f_' + name
        if first_field == 'id':
            first_field = name

        ### determine field type
        ftype = 'string'
        deftypes = {'integer': 'integer', 'double': 'double', 'boolean': 'boolean',
                    'float': 'double', 'bool': 'boolean',
                    'date': 'date', 'time': 'time', 'datetime': 'datetime',
                    'text': 'text', 'file': 'upload', 'image': 'upload',
                    'upload': 'upload', 'wiki': 'text', 'html': 'text'}
        for key, t in deftypes.items():
            if key in has:
                ftype = t
        if refs:
            key = refs[0]
            if not key == 'auth_user':
                key = 't_' + key
            if 'multiple' in has:
                ftype = 'list:reference %s' % key
            else:
                ftype = 'reference %s' % key
        if ftype == 'string' and 'multiple' in has:
            ftype = 'list:string'
        elif ftype == 'integer' and 'multiple' in has:
            ftype = 'list:integer'
        elif name == 'password':
            ftype = 'password'
        s += "    Field('%s', type='%s'" % (name, ftype)

        ### determine field attributes
        if 'notnull' in has or 'notempty' in has or 'required' in has:
            s += ', notnull=True'
        if 'unique' in has:
            s += ', unique=True'
        if ftype == 'boolean' and 'true' in has:
            s += ",\n          default=True"

        ### determine field representation
        elif 'wiki' in has:
            s += ",\n          represent=lambda x, row: MARKMIN(x)"
            s += ",\n          comment='WIKI (markmin)'"
        elif 'html' in has:
            s += ",\n          represent=lambda x, row: XML(x,sanitize=True)"
            s += ",\n          comment='HTML (sanitized)'"
        ### determine field access
        if name == 'password' or has in 'writeonly':
            s += ",\n          readable=False"
        elif 'hidden' in has:
            s += ",\n          writable=False, readable=False"
        elif 'readonly' in has:
            s += ",\n          writable=False"

        ### make up a label
        s += ",\n          label=T('%s')),\n" % \
            ' '.join(x.capitalize() for x in barename.split('_'))
    if table == 'auth_user':
        s += "    Field('created_on','datetime',default=request.now,\n"
        s += "          label=T('Created On'),writable=False,readable=False),\n"
        s += "    Field('modified_on','datetime',default=request.now,\n"
        s += "          label=T('Modified On'),writable=False,readable=False,\n"
        s += "          update=request.now),\n"
        s += "    Field('registration_key',default='',\n"
        s += "          writable=False,readable=False),\n"
        s += "    Field('reset_password_key',default='',\n"
        s += "          writable=False,readable=False),\n"
        s += "    Field('registration_id',default='',\n"
        s += "          writable=False,readable=False),\n"
    elif 'auth_user' in session.app['tables']:
        s += "    auth.signature,\n"
    s += "    format='%(" + first_field + ")s',\n"
    s += "    migrate=settings.migrate)\n\n"
    if table == 'auth_user':
        s += """
db.auth_user.first_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(
    key=auth.settings.hmac_key, min_length=4)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.email.requires = (
    IS_EMAIL(error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
"""
    else:
        s += "db.define_table('%s_archive',db.%s,Field('current_record','reference %s',readable=False,writable=False))\n" % (table, table, table)
    return s
dataset/ETHPy150Open uwdata/termite-data-server/web2py/applications-original/admin/controllers/wizard.py/make_table/swapped operands of `in`