<commit_before>from bookmarks import app, login_manager
from flask import flash, render_template, request, redirect, url_for, abort
from bookmarks.database import db_session
from bookmarks.models import User, Bookmark
from bookmarks.modules.hex_gen import hex_gen
import flask_login


@app.teardown_appcontext
def shutdown_session(exception=None):
    db_session.remove()


@login_manager.user_loader
def load_user(user_id):
    if not User.query.filter(User.id == user_id).first():
        return
    user = flask_login.UserMixin()
    user.id = user_id
    return user


@app.route('/', methods=['GET'])
def front_page():
    bookmarks = Bookmark.query.all()
    return render_template('front_page.html', bookmarks=bookmarks)


@app.route('/add_bookmark/', methods=['GET', 'POST'])
def add_bookmark():
    if request.method == 'POST':
        short = request.form['short']
        link = request.form['link']
        b = Bookmark(short, link, user_id=4)
        db_session.add(b)
        db_session.commit()
        flash('Successfully added {} {}'.format(short, link),
              category='info')
        return redirect(url_for('add_bookmark'), 303)
    else:
        # Generate a possible short
        short = hex_gen()
        # If it exists, keep regenerating<commit_msg>Create bookmarks with current user id<commit_after>from bookmarks import app, login_manager
from flask import flash, render_template, request, redirect, url_for, abort
from bookmarks.database import db_session
from bookmarks.models import User, Bookmark
from bookmarks.modules.hex_gen import hex_gen
import flask_login


@app.teardown_appcontext
def shutdown_session(exception=None):
    db_session.remove()


@login_manager.user_loader
def load_user(user_id):
    if not User.query.filter(User.id == user_id).first():
        return
    user = flask_login.UserMixin()
    user.id = user_id
    return user


@app.route('/', methods=['GET'])
def front_page():
    bookmarks = Bookmark.query.all()
    return render_template('front_page.html', bookmarks=bookmarks)


@app.route('/add_bookmark/', methods=['GET', 'POST'])
@flask_login.login_required
def add_bookmark():
    if request.method == 'POST':
        short = request.form['short']
        link = request.form['link']
        b = Bookmark(short, link, user_id=flask_login.current_user.id)
        db_session.add(b)
        db_session.commit()
        flash('Successfully added {} {}'.format(short, link),
              category='info')
        return redirect(url_for('add_bookmark'), 303)
    else:
        # Generate a possible short
        short = hex_gen()
        # If it exists, keep regenerating
{'fraction_non_alphanumeric': 0.11733535200605602, 'fraction_numerical': 0.0026495079485238456, 'mean_word_length': 3.6696113074204946, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '464042', 'n_tokens_mistral': 814, 'n_tokens_neox': 791, 'n_words': 193}