<commit_before>
from flask import request, redirect, url_for, render_template, flash, abort, Response
from functools import wraps

from app import *
from models import *

def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    user = User.query.filter_by(login=username).first()
    return user and user.check_password(password)

def authenticate():
    """Sends a 401 response that enables basic auth"""
    return Response(
    'Could not verify your access level for that URL.\n'
    'You have to login with proper credentials', 401,
    {'WWW-Authenticate': 'Basic realm="Login Required"'})

def requires_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            return authenticate()
        return f(*args, **kwargs)
    return decorated


def get_posts(post_type, page, per_page):
    pagination = Post.query\
                     .filter_by(post_type=post_type)\
                     .order_by(Post.pub_date.desc())\
                     .paginate(page, per_page)
    return pagination, pagination.items

@app.route('/')
def index():
    note_pagination, notes = get_posts('note', 1, 10)
    article_pagination, articles = get_posts('article', 1, 10)
    return render_template('index.html', notes=notes, articles=articles)

@app.route('/articles', defaults={'page':1})
@app.route('/articles/page/<int:page>')
def articles(page):
    pagination, articles = get_posts('article', page, 10)
    return render_template('articles.html', pagination=pagination, articles=articles)
<commit_msg>remove duplicate auth code<commit_after>
from flask import request, redirect, url_for, render_template, flash, abort, Response
from functools import wraps

from app import *
from models import *
from auth import requires_auth

def get_posts(post_type, page, per_page):
    pagination = Post.query\
                     .filter_by(post_type=post_type)\
                     .order_by(Post.pub_date.desc())\
                     .paginate(page, per_page)
    return pagination, pagination.items

@app.route('/')
def index():
    note_pagination, notes = get_posts('note', 1, 10)
    article_pagination, articles = get_posts('article', 1, 10)
    return render_template('index.html', notes=notes, articles=articles)

@app.route('/articles', defaults={'page':1})
@app.route('/articles/page/<int:page>')
def articles(page):
    pagination, articles = get_posts('article', page, 10)
    return render_template('articles.html', pagination=pagination, articles=articles)

{'fraction_non_alphanumeric': 0.12072207596840917, 'fraction_numerical': 0.009025949605114705, 'mean_word_length': 3.7079646017699117, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '841390', 'n_tokens_mistral': 808, 'n_tokens_neox': 764, 'n_words': 214}