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

"""
byceps.blueprints.party_admin.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

from flask import abort, request

from ...services.ticket import service as ticket_service
from ...util.framework import create_blueprint, flash_error, flash_success
from ...util.templating import templated
from ...util.views import redirect_to

from ..authorization.decorators import permission_required
from ..authorization.registry import permission_registry
from ..brand import service as brand_service
from ..party import service as party_service
from ..shop import article_service, order_service

from .authorization import PartyPermission
from .forms import CreateForm


blueprint = create_blueprint('party_admin', __name__)


permission_registry.register_enum(PartyPermission)


@blueprint.route('/')
@permission_required(PartyPermission.list)
@templated
def index():
    """List parties."""
    parties = party_service.get_all_parties_with_brands()

    return {
        'parties': parties,
    }


@blueprint.route('/brands/<brand_id>', defaults={'page': 1})
@blueprint.route('/brands/<brand_id>/pages/<int:page>')
@permission_required(PartyPermission.list)
@templated
def index_for_brand(brand_id, page):
    """List parties for this brand."""
    brand = brand_service.find_brand(brand_id)
    if brand is None:
        abort(404)

    per_page = request.args.get('per_page', type=int, default=15)
    parties = party_service.get_parties_for_brand_paginated(brand.id, page,
                                                            per_page)

    article_count_by_party_id = article_service.get_article_count_by_party_id()

    order_count_by_party_id = order_service.get_order_count_by_party_id()

    ticket_count_by_party_id = ticket_service.get_ticket_count_by_party_id()

    return {
        'brand': brand,
        'parties': parties,
        'article_count_by_party_id': article_count_by_party_id,
        'order_count_by_party_id': order_count_by_party_id,
        'ticket_count_by_party_id': ticket_count_by_party_id,
    }


@blueprint.route('/<id>')
@permission_required(PartyPermission.list)
@templated
def view(id):
    """Show a party."""
    party = party_service.find_party(id)
    if party is None:
        abort(404)

    return {
        'party': party,
    }


@blueprint.route('/create')
@permission_required(PartyPermission.create)
@templated<commit_msg>Prefix party id URL parameters to prevent overshadowing the `id` built-in<commit_after># -*- coding: utf-8 -*-

"""
byceps.blueprints.party_admin.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

from flask import abort, request

from ...services.ticket import service as ticket_service
from ...util.framework import create_blueprint, flash_error, flash_success
from ...util.templating import templated
from ...util.views import redirect_to

from ..authorization.decorators import permission_required
from ..authorization.registry import permission_registry
from ..brand import service as brand_service
from ..party import service as party_service
from ..shop import article_service, order_service

from .authorization import PartyPermission
from .forms import CreateForm


blueprint = create_blueprint('party_admin', __name__)


permission_registry.register_enum(PartyPermission)


@blueprint.route('/')
@permission_required(PartyPermission.list)
@templated
def index():
    """List parties."""
    parties = party_service.get_all_parties_with_brands()

    return {
        'parties': parties,
    }


@blueprint.route('/brands/<brand_id>', defaults={'page': 1})
@blueprint.route('/brands/<brand_id>/pages/<int:page>')
@permission_required(PartyPermission.list)
@templated
def index_for_brand(brand_id, page):
    """List parties for this brand."""
    brand = brand_service.find_brand(brand_id)
    if brand is None:
        abort(404)

    per_page = request.args.get('per_page', type=int, default=15)
    parties = party_service.get_parties_for_brand_paginated(brand.id, page,
                                                            per_page)

    article_count_by_party_id = article_service.get_article_count_by_party_id()

    order_count_by_party_id = order_service.get_order_count_by_party_id()

    ticket_count_by_party_id = ticket_service.get_ticket_count_by_party_id()

    return {
        'brand': brand,
        'parties': parties,
        'article_count_by_party_id': article_count_by_party_id,
        'order_count_by_party_id': order_count_by_party_id,
        'ticket_count_by_party_id': ticket_count_by_party_id,
    }


@blueprint.route('/<party_id>')
@permission_required(PartyPermission.list)
@templated
def view(party_id):
    """Show a party."""
    party = party_service.find_party(party_id)
    if party is None:
        abort(404)

    return {
        'party': party,
    }


@blueprint.route('/create')
@permission_required(PartyPermission.create)
@templated
{'fraction_non_alphanumeric': 0.11758893280632411, 'fraction_numerical': 0.0071146245059288534, 'mean_word_length': 4.217525773195876, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2123313', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1526, 'n_words': 319}