<commit_before>from flask import Flask, g, render_template, flash, redirect, session, request, url_for, abort


app = Flask(__name__, static_url_path='')
app.config.from_pyfile('config.py')


from models import db, Book, Author
from forms import AuthorForm, BookForm


# ERRORS
if not app.config['DEBUG']:
    @app.errorhandler(404)
    def page_not_found(error):
        return 'This page does not exist', 404

    @app.errorhandler(500)
    def page_not_found(error):
        return 'Server error', 500


# VIEWS
@app.route('/')
def index():
    form = BookForm()
    return render_template('index.html', **locals())


# Books
@app.route('/books/view/all', methods=['GET','POST'])
def books_view_all():
    books = Book.query.all()
    return render_template('books/view.html', **locals())


@app.route('/books/view/<int:book_id>', methods=['GET','POST'])
def books_view(book_id):
    book = Book.query.get_or_404(book_id)
    return render_template('books/view.html', **locals())


@app.route('/books/add/', methods=['GET', 'POST'])
def books_add():
    form = BookForm(request.form)
    form.authors.choices = [(a.id, a.title) for a in Author.query.all()]

    if request.method == "POST" and form.validate():
        # Add book
        pass
        # return redirect(url_for('book_view', book_id=book.id))

    return render_template('books/add.html', **locals())


# Authors
@app.route('/authors/view/all', methods=['GET'])
@app.route('/authors/', methods=['GET'])
def authors_view_all():
    authors = Author.query.all()
    return render_template('authors/view_all.html', **locals())


@app.route('/authors/add/', methods=['GET', 'POST'])
def authors_add():
    form = AuthorForm(request.form)

    if request.method == "POST" and form.validate():
        new_author = Author(title=form.data.get('title'))
        db.session.add(new_author)
        db.session.commit()
        flash("Author added")
        return redirect(url_for('author_view_all'))

    return render_template('authors/add.html', **locals())


@app.route('/authors/edit/<int:author_id>', methods=['GET', 'POST'])
def authors_edit(author_id):
    author = Author.query.get_or_404(author_id)

    form = AuthorForm(request.form, obj=author)

    if request.method == "POST" and form.validate():
        author.title = form.data.get('title')
        db.session.commit()
        flash("Author changed")
        return redirect(url_for('author_view_all'))

    return render_template('authors/edit.html', **locals())


@app.route('/authors/delete/<int:author_id>', methods=['GET', 'POST'])
def authors_delete(author_id):
    author = Author.query.get_or_404(author_id)

    if request.method == "POST":
        db.session.delete(author)
        db.session.commit()
        flash("Author deleted")
        return redirect(url_for('author_view_all'))

    return render_template('authors/delete.html', **locals())
<commit_msg>app: (fix) wrong template<commit_after>from flask import Flask, g, render_template, flash, redirect, session, request, url_for, abort


app = Flask(__name__, static_url_path='')
app.config.from_pyfile('config.py')


from models import db, Book, Author
from forms import AuthorForm, BookForm


# ERRORS
if not app.config['DEBUG']:
    @app.errorhandler(404)
    def page_not_found(error):
        return 'This page does not exist', 404

    @app.errorhandler(500)
    def page_not_found(error):
        return 'Server error', 500


# VIEWS
@app.route('/')
def index():
    form = BookForm()
    return render_template('index.html', **locals())


# Books
@app.route('/books/view/all', methods=['GET','POST'])
def books_view_all():
    books = Book.query.all()
    return render_template('books/view_all.html', **locals())


@app.route('/books/view/<int:book_id>', methods=['GET','POST'])
def books_view(book_id):
    book = Book.query.get_or_404(book_id)
    return render_template('books/view.html', **locals())


@app.route('/books/add/', methods=['GET', 'POST'])
def books_add():
    form = BookForm(request.form)
    form.authors.choices = [(a.id, a.title) for a in Author.query.all()]

    if request.method == "POST" and form.validate():
        # Add book
        pass
        # return redirect(url_for('book_view', book_id=book.id))

    return render_template('books/add.html', **locals())


# Authors
@app.route('/authors/view/all', methods=['GET'])
@app.route('/authors/', methods=['GET'])
def authors_view_all():
    authors = Author.query.all()
    return render_template('authors/view_all.html', **locals())


@app.route('/authors/add/', methods=['GET', 'POST'])
def authors_add():
    form = AuthorForm(request.form)

    if request.method == "POST" and form.validate():
        new_author = Author(title=form.data.get('title'))
        db.session.add(new_author)
        db.session.commit()
        flash("Author added")
        return redirect(url_for('author_view_all'))

    return render_template('authors/add.html', **locals())


@app.route('/authors/edit/<int:author_id>', methods=['GET', 'POST'])
def authors_edit(author_id):
    author = Author.query.get_or_404(author_id)

    form = AuthorForm(request.form, obj=author)

    if request.method == "POST" and form.validate():
        author.title = form.data.get('title')
        db.session.commit()
        flash("Author changed")
        return redirect(url_for('author_view_all'))

    return render_template('authors/edit.html', **locals())


@app.route('/authors/delete/<int:author_id>', methods=['GET', 'POST'])
def authors_delete(author_id):
    author = Author.query.get_or_404(author_id)

    if request.method == "POST":
        db.session.delete(author)
        db.session.commit()
        flash("Author deleted")
        return redirect(url_for('author_view_all'))

    return render_template('authors/delete.html', **locals())

{'fraction_non_alphanumeric': 0.16924931129476584, 'fraction_numerical': 0.007231404958677686, 'mean_word_length': 3.973458904109589, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, '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': '837651', 'n_tokens_mistral': 1945, 'n_tokens_neox': 1854, 'n_words': 369}