<commit_before># -*- coding: utf8 -*-

# Copyright 2015 <NAME>
#
# This file is part of AwesomeShop.
#
# AwesomeShop is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# AwesomeShop is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with eAwesomeShop. If not, see <http://www.gnu.org/licenses/>.

from flask import abort, jsonify, make_response, redirect, \
                  render_template as orig_render_template, request
from flask_login import current_user
from jinja2.exceptions import TemplateNotFound

from . import app, get_locale, login_required, admin_required, messages, pdf

from .shop.models.order import Order

def render_template(template, **context):
    context['locale'] = get_locale()
    return orig_render_template(template, **context)

@app.route('/')
@app.route('/<path:path>')
def shop(path=None):
    return render_template('shop.html')

@app.route('/login', methods=['GET','POST'])
def login():
    return render_template('login.html')

@app.route('/messages')
def messages_route():
    return jsonify(messages.messages())

@app.route('/confirm/<code>')
@login_required
def confirm_email(code):
    if code == current_user.confirm_code:
        current_user.confirm_code = None
        current_user.save()
    # XXX Redirect the user to a specific message
    return redirect('/')

@app.route('/part/<partname>')
def part(partname):
    try:
        return render_template('part/{}.html'.format(partname))
    except TemplateNotFound:
        abort(404)

@app.route('/shop/<partname>')
def shop_part(partname):
    try:
        return render_template('shop/{}.html'.format(partname))
    except TemplateNotFound:
        abort(404)

@app.route('/dashboard')
@app.route('/dashboard/')
def dashboard():
    return render_template('dashboard.html')

@app.route('/dashboard/<partname>')
@admin_required
def dashboard_part(partname):
    try:
        return render_template('dashboard/{}.html'.format(partname))
    except TemplateNotFound:
        abort(404)

@app.route('/api/config')
def api_config():
    return jsonify(
            languages=app.config['LANGS']
            )

@app.route('/pdf/invoice/<number>')
def pdf_invoice(number):
    if current_user.is_admin:
        order = Order.objects.get_or_404(invoice_number=number)
    else:
        order = Order.objects.get_or_404(
                    customer=current_user.to_dbref(),
                    invoice_number=number
                    )
    response = make_response(pdf.invoice(order))
    response.mimetype = 'application/pdf'
    return response


@app.errorhandler(401)
def unauthorized(e):
    return jsonify(error='401', message='Unauthorized'), 401

@app.errorhandler(403)
def forbidden(e):
    return jsonify(error='403', message='Forbidden'), 403

@app.errorhandler(404)
def notfound(e):
    return jsonify(error='404', message='Not Found'), 404

@app.errorhandler(500)
def internalservererror(e):
    return jsonify(error='500', message='Internal Server Error'), 500
<commit_msg>Convert a "XXX" to a "TODO"<commit_after># -*- coding: utf8 -*-

# Copyright 2015 <NAME>
#
# This file is part of AwesomeShop.
#
# AwesomeShop is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# AwesomeShop is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with eAwesomeShop. If not, see <http://www.gnu.org/licenses/>.

from flask import abort, jsonify, make_response, redirect, \
                  render_template as orig_render_template, request
from flask_login import current_user
from jinja2.exceptions import TemplateNotFound

from . import app, get_locale, login_required, admin_required, messages, pdf

from .shop.models.order import Order

def render_template(template, **context):
    context['locale'] = get_locale()
    return orig_render_template(template, **context)

@app.route('/')
@app.route('/<path:path>')
def shop(path=None):
    return render_template('shop.html')

@app.route('/login', methods=['GET','POST'])
def login():
    return render_template('login.html')

@app.route('/messages')
def messages_route():
    return jsonify(messages.messages())

@app.route('/confirm/<code>')
@login_required
def confirm_email(code):
    if code == current_user.confirm_code:
        current_user.confirm_code = None
        current_user.save()
    # TODO Redirect the user to a specific message
    return redirect('/')

@app.route('/part/<partname>')
def part(partname):
    try:
        return render_template('part/{}.html'.format(partname))
    except TemplateNotFound:
        abort(404)

@app.route('/shop/<partname>')
def shop_part(partname):
    try:
        return render_template('shop/{}.html'.format(partname))
    except TemplateNotFound:
        abort(404)

@app.route('/dashboard')
@app.route('/dashboard/')
def dashboard():
    return render_template('dashboard.html')

@app.route('/dashboard/<partname>')
@admin_required
def dashboard_part(partname):
    try:
        return render_template('dashboard/{}.html'.format(partname))
    except TemplateNotFound:
        abort(404)

@app.route('/api/config')
def api_config():
    return jsonify(
            languages=app.config['LANGS']
            )

@app.route('/pdf/invoice/<number>')
def pdf_invoice(number):
    if current_user.is_admin:
        order = Order.objects.get_or_404(invoice_number=number)
    else:
        order = Order.objects.get_or_404(
                    customer=current_user.to_dbref(),
                    invoice_number=number
                    )
    response = make_response(pdf.invoice(order))
    response.mimetype = 'application/pdf'
    return response


@app.errorhandler(401)
def unauthorized(e):
    return jsonify(error='401', message='Unauthorized'), 401

@app.errorhandler(403)
def forbidden(e):
    return jsonify(error='403', message='Forbidden'), 403

@app.errorhandler(404)
def notfound(e):
    return jsonify(error='404', message='Not Found'), 404

@app.errorhandler(500)
def internalservererror(e):
    return jsonify(error='500', message='Internal Server Error'), 500

{'fraction_non_alphanumeric': 0.12276882890727035, 'fraction_numerical': 0.016833551008561893, 'mean_word_length': 3.9440459110473456, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3352117', 'n_tokens_mistral': 2108, 'n_tokens_neox': 2012, 'n_words': 557}