<commit_before>from flask import (
    Blueprint,
    abort,
    redirect,
    render_template,
    request,
    url_for
)

from application.models import User

frontend = Blueprint('frontend', __name__, template_folder='templates')


@frontend.route('/')
def index():
    users = User.objects.all()
    return render_template('index.html', users=users)


def get_or_404(model, **kwargs):
    try:
        return model.objects.get(**kwargs)

    except model.DoesNotExist:
        abort(404)


@frontend.route('/links/<id>', methods=['GET', 'POST'])
def links(id):
    user = get_or_404(User, id=id)

    if request.method == 'POST':
        other = get_or_404(User, id=request.form.get('user_id'))
        user.link(other)
        return redirect(url_for('.index'))

    if request.is_xhr:
        return json.dumps({'ids': [
            u.user_id for u in user.linked_ids]})

    return render_template('links.html', user=user)<commit_msg>Separate endpoint for JSON links<commit_after>import json

from flask import (
    Blueprint,
    abort,
    redirect,
    render_template,
    request,
    url_for
)

from application.models import User


frontend = Blueprint('frontend', __name__, template_folder='templates')


@frontend.route('/')
def index():
    users = User.objects.all()
    return render_template('index.html', users=users)


def get_or_404(model, **kwargs):
    try:
        return model.objects.get(**kwargs)

    except model.DoesNotExist:
        abort(404)


@frontend.route('/links/<id>', methods=['GET', 'POST'])
def links(id):
    user = get_or_404(User, id=id)

    if request.method == 'POST':
        other = get_or_404(User, id=request.form.get('user_id'))
        user.link(other)
        return redirect(url_for('.index'))

    return render_template('links.html', user=user)


@frontend.route('/links/<id>.json')
def links_json(id):
    user = get_or_404(User, id=id)

    return json.dumps({'ids': [
        u.user_id for u in user.linked_ids]})
{'fraction_non_alphanumeric': 0.14516944865958523, 'fraction_numerical': 0.013657056145675266, 'mean_word_length': 3.385809312638581, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5190206', 'n_tokens_mistral': 684, 'n_tokens_neox': 649, 'n_words': 135}