def sort_tables(tables):
    import re
    regex = re.compile('(%s)' % '|'.join(tables))
    is_auth_user = 'auth_user' in tables
    d = {}
    for table in tables:
        d[table] = []
        for field in session.app[table % 'table_%s']:
            d[table] += regex.findall(field)
    tables = []
    if is_auth_user:
        tables.append('auth_user')

    def append(table, trail=[]):
        if table in trail:
            raise RuntimeError
        for t in d[table]:
            # if not t==table: (problem, no dropdown for self references)
            append(t, trail=trail + [table])
        if not table in tables:
            tables.append(table)
    for table in d:
        append(table)
    return tables
dataset/ETHPy150Open uwdata/termite-data-server/web2py/applications-original/admin/controllers/wizard.py/sort_tables/swapped operands of `%`