コード例 #1
0
def render_Dirichletwebpage(modulus=None, orbit_label=None, number=None):

    if number is None and orbit_label is None and re.match(
            r'^[1-9][0-9]*\.[1-9][0-9]*$', modulus):
        modulus, number = modulus.split('.')
        return redirect(
            url_for(".render_Dirichletwebpage", modulus=modulus,
                    number=number), 301)

    args = {}
    args['type'] = 'Dirichlet'
    args['modulus'] = modulus
    args['orbit_label'] = orbit_label
    args['number'] = number
    try:
        modulus = int(modulus)
    except ValueError:
        modulus = 0
    if modulus <= 0:
        flash_error(
            "%s is not a valid modulus for a Dirichlet character. It should be a positive integer.",
            args['modulus'])
        return redirect(url_for(".render_DirichletNavigation"))
    if modulus > 10**20:
        flash_error(
            "specified modulus %s is too large, it should be less than $10^{20}$.",
            modulus)
        return redirect(url_for(".render_DirichletNavigation"))

    if number is None:
        if orbit_label is None:

            if modulus <= 10000:
                info = WebDBDirichletGroup(**args).to_dict()
                info['show_orbit_label'] = True
            else:
                info = WebSmallDirichletGroup(**args).to_dict()

            info['title'] = 'Group of Dirichlet characters of modulus ' + str(
                modulus)
            info['bread'] = bread([('%s' % modulus,
                                    url_for(".render_Dirichletwebpage",
                                            modulus=modulus))])
            info['learnmore'] = learn()
            info['code'] = dict([(k[4:], info[k]) for k in info
                                 if k[0:4] == "code"])
            info['code']['show'] = {lang: ''
                                    for lang in info['codelangs']
                                    }  # use default show names
            if 'gens' in info:
                info['generators'] = ', '.join(
                    r'<a href="%s">$\chi_{%s}(%s,\cdot)$' % (url_for(
                        ".render_Dirichletwebpage", modulus=modulus, number=g),
                                                             modulus, g)
                    for g in info['gens'])
            return render_template('CharGroup.html', **info)
        else:
            if modulus <= 10000:
                try:
                    info = WebDBDirichletOrbit(**args).to_dict()
                except ValueError:
                    flash_error(
                        "No Galois orbit of Dirichlet characters with label %s.%s was found in the database.",
                        modulus, orbit_label)
                    return redirect(url_for(".render_DirichletNavigation"))

                info['show_orbit_label'] = True
                info['downloads'] = [
                    ('Underlying data',
                     url_for('.dirchar_data',
                             label=f"{modulus}.{orbit_label}"))
                ]
                info['learnmore'] = learn()
                info['code'] = dict([(k[4:], info[k]) for k in info
                                     if k[0:4] == "code"])
                info['code']['show'] = {
                    lang: ''
                    for lang in info['codelangs']
                }  # use default show names
                info['bread'] = bread([('%s' % modulus,
                                        url_for(".render_Dirichletwebpage",
                                                modulus=modulus)),
                                       ('%s' % orbit_label,
                                        url_for(".render_Dirichletwebpage",
                                                modulus=modulus,
                                                orbit_label=orbit_label))])
                return render_template('CharacterGaloisOrbit.html', **info)
            else:
                flash_error(
                    "Galois orbits have only been computed for modulus up to 10,000, but you entered %s",
                    modulus)
            return redirect(url_for(".render_DirichletNavigation"))

    try:
        number = label_to_number(modulus, number)
    except ValueError:
        flash_error(
            "the value %s is invalid. It should either be a positive integer "
            "coprime to and no greater than the modulus %s, or a letter that "
            "corresponds to a valid orbit index.", args['number'],
            args['modulus'])
        return redirect(url_for(".render_DirichletNavigation"))

    if modulus <= 10000:
        db_orbit_label = db.char_dir_values.lookup("{}.{}".format(
            modulus, number),
                                                   projection='orbit_label')
        # The -1 in the line below is because labels index at 1, not 0
        real_orbit_label = cremona_letter_code(
            int(db_orbit_label.partition('.')[-1]) - 1)
        if orbit_label is not None:
            if orbit_label != real_orbit_label:
                flash_warning(
                    "The supplied character orbit label %s.%s was wrong. "
                    "The correct orbit label is %s.%s. The URL has been duly corrected.",
                    modulus, orbit_label, modulus, real_orbit_label)
                return redirect(
                    url_for("characters.render_Dirichletwebpage",
                            modulus=modulus,
                            orbit_label=real_orbit_label,
                            number=number))
        args['orbit_label'] = real_orbit_label
        downloads = [('Underlying data',
                      url_for(".dirchar_data",
                              label=f"{modulus}.{real_orbit_label}.{number}"))]
    else:
        if orbit_label is not None:
            flash_warning(
                "You entered the character orbit label %s.%s. However, such labels "
                "have not been computed for this modulus. The supplied orbit "
                "label has therefore been ignored and expunged from the URL.",
                modulus, orbit_label)
            return redirect(
                url_for("characters.render_Dirichletwebpage",
                        modulus=modulus,
                        number=number))
        downloads = []

    args['number'] = number
    webchar, bread_crumbs = make_webchar(args, get_bread=True)
    info = webchar.to_dict()
    info['bread'] = bread_crumbs
    info['learnmore'] = learn()
    info['downloads'] = downloads
    info['code'] = dict([(k[4:], info[k]) for k in info if k[0:4] == "code"])
    info['code']['show'] = {lang: ''
                            for lang in info['codelangs']
                            }  # use default show names
    info['KNOWL_ID'] = 'character.dirichlet.%s.%s' % (modulus, number)
    return render_template('Character.html', **info)