<commit_before>from flask import Blueprint, redirect, render_template, url_for
from flask_login import current_user
from app.models import Post


mod = Blueprint('index', __name__)


@mod.route('/', defaults={'page': 1})
@mod.route('/page/<int:page>/')
def index(page):
    if current_user.is_authenticated:
        posts = Post.select().where(Post.is_page == False).order_by(Post.timestamp.desc())
    else:
        posts = Post.select().where((Post.is_page == False) &
                                    (Post.published == True)
                                    ).order_by(Post.timestamp.desc())

    pagination = posts.paginate(page, 5)

    if not pagination:
        if posts:
            last_page = (len(posts) // 5) + 1
            return redirect(url_for('.index', page=last_page))

    has_next = True if posts.paginate(page+1, 5) else False

    return render_template('index.html',
                           pagination=pagination,
                           page=page,
                           has_next=has_next)<commit_msg>'and' instead of nested ifs<commit_after>from flask import Blueprint, redirect, render_template, url_for
from flask_login import current_user
from app.models import Post


mod = Blueprint('index', __name__)


@mod.route('/', defaults={'page': 1})
@mod.route('/page/<int:page>/')
def index(page):
    if current_user.is_authenticated:
        posts = Post.select().where(Post.is_page == False).order_by(Post.timestamp.desc())
    else:
        posts = Post.select().where((Post.is_page == False) &
                                    (Post.published == True)
                                    ).order_by(Post.timestamp.desc())

    pagination = posts.paginate(page, 5)

    if not pagination and posts:
        last_page = (len(posts) // 5) + 1
        return redirect(url_for('.index', page=last_page))

    has_next = True if posts.paginate(page+1, 5) else False

    return render_template('index.html',
                           pagination=pagination,
                           page=page,
                           has_next=has_next)
{'fraction_non_alphanumeric': 0.12332053742802303, 'fraction_numerical': 0.005758157389635317, 'mean_word_length': 2.17351598173516, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3554361', 'n_tokens_mistral': 616, 'n_tokens_neox': 584, 'n_words': 129}