def set_info_for_gamma1(level,weight,weight2=None):
    from lmfdb.modular_forms.elliptic_modular_forms.backend.emf_utils import dimension_from_db,dirichlet_character_conrey_galois_orbits_reps
    from sage.all import DirichletGroup
    from dirichlet_conrey import DirichletGroup_conrey
    G = dirichlet_character_conrey_galois_orbits_reps(level)
    dim_table = dimension_from_db(level,weight,chi='all',group='gamma1')
    if weight<> None and weight2>weight:
        w1 = weight; w2 = weight2
    else:
        w1 = weight; w2 = weight
    table = {'galois_orbit':{},'galois_orbits_reps':{},'cells':{}}
    table['weights']=range(w1,w2+1)
    max_gal_count = 0
    from  lmfdb.base import getDBConnection
    db = getDBConnection()['modularforms2']['webmodformspace']
    for x in G:
        xi = x.number()
        table['galois_orbits_reps'][xi]= {'head' : "\(\chi_{" + str(level) + "}(" + str(xi) + ",\cdot) \)",
                                              'chi': str(x.number()),
                                              'url': url_for('characters.render_Dirichletwebpage', modulus=level, number=xi) }
        table['galois_orbit'][xi]= [
            {'head' : "\({0}\)".format(xc.number()),
             'chi': str(xc.number()),
             'url': url_for('characters.render_Dirichletwebpage', modulus=level, number=xc.number()) }
            for xc in x.galois_orbit()]
        tmp_gal_count = len(table['galois_orbit'][xi])
        if tmp_gal_count > max_gal_count:
            max_gal_count = tmp_gal_count
        table['cells'][xi]={}
        orbit = map(lambda x:x.number(),x.galois_orbit()) 
        for k in range(w1,w2+1):
            # try:
            #     d,t = dim_table[level][weight][xi]
            # except KeyError:
            #     d = -1; t = 0
            r = db.find_one({'level':int(level),'weight':int(k),'character':{"$in":orbit}})
            if not r is None:
                d = r.get('dimension',"n/a")
                url = url_for(
                    'emf.render_elliptic_modular_forms', level=level, weight=k, character=xi)
            else:
                url = ''
                d = "n/a"
            table['cells'][xi][k] ={'N': level, 'k': k, 'chi': xi, 'url': url, 'dim': d}
    table['galois_orbits_reps_numbers']=table['galois_orbits_reps'].keys()
    table['galois_orbits_reps_numbers'].sort()
    table['maxGalCount']=max_gal_count
    return table
def set_info_for_gamma1(level,weight,weight2=None):
    from lmfdb.modular_forms.elliptic_modular_forms.backend.emf_utils import dimension_from_db,dirichlet_character_conrey_galois_orbits_reps
    from sage.all import DirichletGroup
    from dirichlet_conrey import DirichletGroup_conrey
    G = dirichlet_character_conrey_galois_orbits_reps(level)
    dim_table = dimension_from_db(level,weight,chi='all',group='gamma1')
    if weight<> None and weight2>weight:
        w1 = weight; w2 = weight2
    else:
        w1 = weight; w2 = weight
    table = {'galois_orbit':{},'galois_orbits_reps':{},'cells':{}}
    table['weights']=range(w1,w2+1)
    max_gal_count = 0 
    for x in G:
        xi = x.number()
        table['galois_orbits_reps'][xi]= {'head' : "\(\chi_{" + str(level) + "}(" + str(xi) + ",\cdot) \)",
                                              'chi': str(x.number()),
                                              'url': url_for('characters.render_Dirichletwebpage', modulus=level, number=xi) }
        table['galois_orbit'][xi]= [
            {'head' : "\({0}\)".format(xc.number()),
             'chi': str(xc.number()),
             'url': url_for('characters.render_Dirichletwebpage', modulus=level, number=xc.number()) }
            for xc in x.galois_orbit()]
        tmp_gal_count = len(table['galois_orbit'][xi])
        if tmp_gal_count > max_gal_count:
            max_gal_count = tmp_gal_count
        table['cells'][xi]={}
        for k in range(w1,w2+1):
            try:
                d,t = dim_table[level][weight][xi]
            except KeyError:
                d = -1; t = 0
            if t<>0:
                url = url_for(
                    'emf.render_elliptic_modular_forms', level=level, weight=weight, character=xi)
            else:
                url = ''
            table['cells'][xi][k] ={'N': level, 'k': k, 'chi': xi, 'url': url, 'dim': d}
    table['galois_orbits_reps_numbers']=table['galois_orbits_reps'].keys()
    table['galois_orbits_reps_numbers'].sort()
    table['maxGalCount']=max_gal_count
    return table