<commit_before># -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.

from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _

from shoop.admin.utils.picotable import (
    Column, TextFilter, true_or_false_filter
)
from shoop.admin.utils.views import PicotableListView
from shoop.core.models import PaymentMethod, ShippingMethod


class ServiceListView(PicotableListView):
    model = None  # Override in subclass
    columns = []
    base_columns = [
        Column(
            "name", _("Name"), sort_field="translations__name",
            filter_config=TextFilter(filter_field="translations__name", placeholder=_("Filter by name..."))
        ),
        Column("enabled", _(u"Enabled"), filter_config=true_or_false_filter),
        Column("shop", _(u"Shop"))
    ]

    def get_object_abstract(self, instance, item):
        return [
            {"text": "%s" % instance, "class": "header"},
        ]


class ShippingMethodListView(ServiceListView):
    model = ShippingMethod

    def __init__(self, **kwargs):
        self.columns = self.base_columns + [Column("carrier", _("Carrier"))]
        super(ShippingMethodListView, self).__init__(**kwargs)


class PaymentMethodListView(ServiceListView):
    model = PaymentMethod

    def __init__(self, **kwargs):
        self.columns = self.base_columns + [Column("payment_processor", _("Payment Processor"))]
        super(PaymentMethodListView, self).__init__(**kwargs)<commit_msg>Admin: Show service choice name in service provider admin<commit_after># -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.

from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _

from shoop.admin.utils.picotable import (
    Column, TextFilter, true_or_false_filter
)
from shoop.admin.utils.views import PicotableListView
from shoop.core.models import PaymentMethod, ShippingMethod


class ServiceListView(PicotableListView):
    model = None  # Override in subclass
    columns = []
    base_columns = [
        Column(
            "name", _("Name"), sort_field="translations__name",
            filter_config=TextFilter(filter_field="translations__name", placeholder=_("Filter by name..."))
        ),
        Column(
            "choice_identifier", _(u"Service choice"), display="format_service_choice",
            sortable=False,
        ),
        Column("enabled", _(u"Enabled"), filter_config=true_or_false_filter),
        Column("shop", _(u"Shop"))
    ]

    def get_object_abstract(self, instance, item):
        return [
            {"text": "%s" % instance, "class": "header"},
        ]

    def format_service_choice(self, instance, *args, **kwargs):
        for choice in instance.provider.get_service_choices():
            if choice.identifier == instance.choice_identifier:
                return str(choice.name)


class ShippingMethodListView(ServiceListView):
    model = ShippingMethod

    def __init__(self, **kwargs):
        self.columns = self.base_columns + [Column("carrier", _("Carrier"))]
        super(ShippingMethodListView, self).__init__(**kwargs)


class PaymentMethodListView(ServiceListView):
    model = PaymentMethod

    def __init__(self, **kwargs):
        self.columns = self.base_columns + [Column("payment_processor", _("Payment Processor"))]
        super(PaymentMethodListView, self).__init__(**kwargs)
{'fraction_non_alphanumeric': 0.11285600212935853, 'fraction_numerical': 0.005323396326856534, 'mean_word_length': 3.6337854500616524, 'pattern_counts': {'":': 4, '<': 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': '5904094', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1028, 'n_words': 271}