<commit_before># -*- coding: utf-8 -*-

"""
byceps.blueprints.user_admin.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2015 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from flask import request

from ...database import db
from ...util.framework import create_blueprint
from ...util.templating import templated

from ..authorization.decorators import permission_required
from ..authorization.registry import permission_registry
from ..shop.service import get_orders_placed_by_user
from ..user.models import User

from .authorization import UserPermission


blueprint = create_blueprint('user_admin', __name__)


permission_registry.register_enum(UserPermission)


@blueprint.route('/', defaults={'page': 1})
@blueprint.route('/pages/<int:page>')
@permission_required(UserPermission.list)
@templated
def index(page):
    """List users."""
    query = User.query \
        .options(db.joinedload('detail')) \
        .order_by(User.created_at.desc())

    search_term = request.args.get('search_term', default='').strip()
    if search_term:
        query = query \
            .filter(User.screen_name.ilike('%{}%'.format(search_term)))

        only = None<commit_msg>Include first and last names when searching in the admin's list of users.<commit_after># -*- coding: utf-8 -*-

"""
byceps.blueprints.user_admin.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2015 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from flask import request

from ...database import db
from ...util.framework import create_blueprint
from ...util.templating import templated

from ..authorization.decorators import permission_required
from ..authorization.registry import permission_registry
from ..shop.service import get_orders_placed_by_user
from ..user.models import User, UserDetail

from .authorization import UserPermission


blueprint = create_blueprint('user_admin', __name__)


permission_registry.register_enum(UserPermission)


@blueprint.route('/', defaults={'page': 1})
@blueprint.route('/pages/<int:page>')
@permission_required(UserPermission.list)
@templated
def index(page):
    """List users."""
    query = User.query \
        .options(db.joinedload('detail')) \
        .order_by(User.created_at.desc())

    search_term = request.args.get('search_term', default='').strip()
    if search_term:
        ilike_pattern = '%{}%'.format(search_term)
        query = query \
            .join(UserDetail) \
            .filter(
                db.or_(
                    User.screen_name.ilike(ilike_pattern),
                    UserDetail.first_names.ilike(ilike_pattern),
                    UserDetail.last_name.ilike(ilike_pattern)
                )
            )

        only = None
{'fraction_non_alphanumeric': 0.14635036496350365, 'fraction_numerical': 0.0072992700729927005, 'mean_word_length': 3.5607321131447587, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5517042', 'n_tokens_mistral': 810, 'n_tokens_neox': 771, 'n_words': 175}