<commit_before>from flask import render_template, request, g, abort, make_response
from flask_login import login_required

from .. import c3bottles, db

from ..model.drop_point import DropPoint


@c3bottles.route("/create", methods=("GET", "POST"))
@c3bottles.route(
    "/create/<int:level>/<float:lat>/<float:lng>",
    methods=("GET", "POST")
)
@login_required
def create_dp(lat=None, lng=None, level=None, description=None, errors=None):

    if not g.user.can_edit:
        abort(401)

    if request.method == "POST":
        number = request.form.get("number")
        description = request.form.get("description")
        lat = float(request.form.get("lat"))
        lng = float(request.form.get("lng"))
        level = int(request.form.get("level"))
        try:
            DropPoint(
                number=number, description=description, lat=lat,
                lng=lng, level=level
            )
        except ValueError as e:
            errors = e.args
        else:
            db.session.commit()
            return render_template(
                "success.html",
                text="Your drop point has been created successfully."
            )
    else:
        number = DropPoint.get_next_free_number()

    if errors is not None:
        error_list = [v for d in errors for v in d.values()]
        error_fields = [k for d in errors for k in d.keys()]
    else:
        error_list = []
        error_fields = []

    return render_template(
        "create_dp.html",
        number=number,
        lat=lat,
        lng=lng,
        level=level,
        description=description,
        error_list=error_list,
        error_fields=error_fields,
    )


@c3bottles.route("/create.js/<int:level>/<float:lat>/<float:lng>")
def create_dp_js(level, lat, lng):
    resp = make_response(render_template(
        "js/create_dp.js",
        all_dps_json=DropPoint.get_dps_json(),
        level=level,
        lat=lat,
        lng=lng
    ))
    resp.mimetype = "application/javascript"
    return resp<commit_msg>Enable drop point creation in level -1<commit_after>from flask import render_template, request, g, abort, make_response
from flask_login import login_required

from .. import c3bottles, db

from ..model.drop_point import DropPoint


@c3bottles.route("/create", methods=("GET", "POST"))
@c3bottles.route(
    "/create/<level>/<float:lat>/<float:lng>",
    methods=("GET", "POST")
)
@login_required
def create_dp(lat=None, lng=None, level=None, description=None, errors=None):

    if not g.user.can_edit:
        abort(401)

    if request.method == "POST":
        number = request.form.get("number")
        description = request.form.get("description")
        lat = float(request.form.get("lat"))
        lng = float(request.form.get("lng"))
        level = int(request.form.get("level"))
        try:
            DropPoint(
                number=number, description=description, lat=lat,
                lng=lng, level=level
            )
        except ValueError as e:
            errors = e.args
        else:
            db.session.commit()
            return render_template(
                "success.html",
                text="Your drop point has been created successfully."
            )
    else:
        number = DropPoint.get_next_free_number()

    if errors is not None:
        error_list = [v for d in errors for v in d.values()]
        error_fields = [k for d in errors for k in d.keys()]
    else:
        error_list = []
        error_fields = []

    return render_template(
        "create_dp.html",
        number=number,
        lat=lat,
        lng=lng,
        level=int(level),
        description=description,
        error_list=error_list,
        error_fields=error_fields,
    )


@c3bottles.route("/create.js/<level>/<float:lat>/<float:lng>")
def create_dp_js(level, lat, lng):
    resp = make_response(render_template(
        "js/create_dp.js",
        all_dps_json=DropPoint.get_dps_json(),
        level=int(level),
        lat=lat,
        lng=lng
    ))
    resp.mimetype = "application/javascript"
    return resp
{'fraction_non_alphanumeric': 0.12160508930756056, 'fraction_numerical': 0.0036701737215561535, 'mean_word_length': 2.3128038897893033, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, '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': '6927035', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1261, 'n_words': 271}