<commit_before>
from flask.ext.paginate import Pagination


from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter

from ..config import *

from ..tools import get_reports

from api import *
from login import *
from users import *


@app.route('/reports/<int:report_number>')
def view_report(report_number):
    with open(os.path.join(UPLOAD_FOLDER, 'crash_report_%d.json' % report_number)) as r:
        payload = json.load(r)
        pylexer = PythonLexer(stripall=True)
        for tb in payload['Traceback']:
            highlighted_line = [tb['Error Line Number'] - tb['Source Code'][0][0] + 1]
            htmlformatter = HtmlFormatter(linenos=True,
                                          cssclass='highlight',
                                          linenostart=tb['Source Code'][0][0],
                                          hl_lines=highlighted_line)
            src = highlight(''.join(t[1] for t in tb['Source Code']), pylexer, htmlformatter)
            tb['Source Code'] = src
        html = render_template('crashreport.html',
                               info=payload,
                               inspection_level=10000,
                               user=flask_login.current_user)
        return html


@app.route('/')
@flask_login.login_required
def home():
    PER_PAGE = 10
    reports = get_reports()
    n_total_reports = len(reports)
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1
    reports = reports[(page-1) * PER_PAGE: page * PER_PAGE]
    pagination = Pagination(page=page, total=n_total_reports, search=False, record_name='reports')
    html = render_template('index.html', reports=reports, user=flask_login.current_user, pagination=pagination)
    return html<commit_msg>show 50 reports per page and always start off at the last page by default<commit_after>
from flask.ext.paginate import Pagination


from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter

from ..config import *

from ..tools import get_reports

from api import *
from login import *
from users import *


@app.route('/reports/<int:report_number>')
def view_report(report_number):
    with open(os.path.join(UPLOAD_FOLDER, 'crash_report_%d.json' % report_number)) as r:
        payload = json.load(r)
        pylexer = PythonLexer(stripall=True)
        for tb in payload['Traceback']:
            highlighted_line = [tb['Error Line Number'] - tb['Source Code'][0][0] + 1]
            htmlformatter = HtmlFormatter(linenos=True,
                                          cssclass='highlight',
                                          linenostart=tb['Source Code'][0][0],
                                          hl_lines=highlighted_line)
            src = highlight(''.join(t[1] for t in tb['Source Code']), pylexer, htmlformatter)
            tb['Source Code'] = src
        html = render_template('crashreport.html',
                               info=payload,
                               inspection_level=10000,
                               user=flask_login.current_user)
        return html


@app.route('/')
@flask_login.login_required
def home():
    PER_PAGE = 50
    reports = get_reports()
    n_total_reports = len(reports)
    try:
        page = max(1, int(request.args.get('page', n_total_reports / PER_PAGE)))
    except ValueError:
        page = 1
    reports = reports[(page-1) * PER_PAGE: page * PER_PAGE]
    pagination = Pagination(page=page, per_page=PER_PAGE, total=n_total_reports, search=False, record_name='reports')
    html = render_template('index.html', reports=reports, user=flask_login.current_user, pagination=pagination)
    return html
{'fraction_non_alphanumeric': 0.10355815188528943, 'fraction_numerical': 0.009028146574614976, 'mean_word_length': 2.430783242258652, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1192071', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1056, 'n_words': 250}