<commit_before>from dmutils.audit import AuditTypes

from flask import jsonify, abort, request, current_app
from datetime import datetime

from .. import main
from ...models import ArchivedService, Service, Supplier, Framework

from sqlalchemy import asc
from ...validation import is_valid_service_id_or_400
from ...utils import url_for, pagination_links, drop_foreign_fields, display_list, strip_whitespace_from_data, \
    get_valid_page_or_1

from ...service_utils import (
    validate_and_return_service_request,
    update_and_validate_service,
    index_service,
    delete_service_from_index,
    validate_and_return_updater_request,
    commit_and_archive_service,
    validate_service,
    drop_api_exported_fields_so_that_api_import_will_validate
)


@main.route('/')
def index():
    """Entry point for the API, show the resources that are available."""
    return jsonify(links={
        "audits.list": url_for('.list_audits', _external=True),
        "services.list": url_for('.list_services', _external=True),
        "suppliers.list": url_for('.list_suppliers', _external=True),
        "frameworks.list": url_for('.list_frameworks', _external=True),
    }
    ), 200


@main.route('/services', methods=['GET'])
def list_services():
    page = get_valid_page_or_1()

    supplier_id = request.args.get('supplier_id')

    if request.args.get('framework'):
        services = Service.query.has_frameworks(*request.args['framework'].split(','))
    else:
        services = Service.query.framework_is_live()

    if request.args.get('status'):
        services = services.has_statuses(*request.args['status'].split(','))

    if supplier_id is not None:
        try:
            supplier_id = int(supplier_id)
        except ValueError:
            abort(400, "Invalid supplier_id: %s" % supplier_id)

        supplier = Supplier.query.filter(Supplier.supplier_id == supplier_id).all()
        if not supplier:
            abort(404, "supplier_id '%d' not found" % supplier_id)

        items = services.default_order().filter(Service.supplier_id == supplier_id).all()<commit_msg>Strip whitespace from status and framework /services params<commit_after>from dmutils.audit import AuditTypes

from flask import jsonify, abort, request, current_app
from datetime import datetime

from .. import main
from ...models import ArchivedService, Service, Supplier, Framework

from sqlalchemy import asc
from ...validation import is_valid_service_id_or_400
from ...utils import url_for, pagination_links, drop_foreign_fields, display_list, strip_whitespace_from_data, \
    get_valid_page_or_1

from ...service_utils import (
    validate_and_return_service_request,
    update_and_validate_service,
    index_service,
    delete_service_from_index,
    validate_and_return_updater_request,
    commit_and_archive_service,
    validate_service,
    drop_api_exported_fields_so_that_api_import_will_validate
)


@main.route('/')
def index():
    """Entry point for the API, show the resources that are available."""
    return jsonify(links={
        "audits.list": url_for('.list_audits', _external=True),
        "services.list": url_for('.list_services', _external=True),
        "suppliers.list": url_for('.list_suppliers', _external=True),
        "frameworks.list": url_for('.list_frameworks', _external=True),
    }
    ), 200


@main.route('/services', methods=['GET'])
def list_services():
    page = get_valid_page_or_1()

    supplier_id = request.args.get('supplier_id')

    if request.args.get('framework'):
        services = Service.query.has_frameworks(*[
            slug.strip() for slug in request.args['framework'].split(',')
        ])
    else:
        services = Service.query.framework_is_live()

    if request.args.get('status'):
        services = services.has_statuses(*[
            status.strip() for status in request.args['status'].split(',')
        ])

    if supplier_id is not None:
        try:
            supplier_id = int(supplier_id)
        except ValueError:
            abort(400, "Invalid supplier_id: %s" % supplier_id)

        supplier = Supplier.query.filter(Supplier.supplier_id == supplier_id).all()
        if not supplier:
            abort(404, "supplier_id '%d' not found" % supplier_id)

        items = services.default_order().filter(Service.supplier_id == supplier_id).all()
{'fraction_non_alphanumeric': 0.11231549815498156, 'fraction_numerical': 0.006457564575645757, 'mean_word_length': 3.7816979051819186, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '327321', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1299, 'n_words': 278}