<commit_before># This file is part of Shuup.
#
# 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 import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import string_concat

from shuup.admin.utils.picotable import Column
from shuup.admin.utils.views import CreateOrUpdateView, PicotableListView
from shuup.default_tax.models import TaxRule
from shuup.utils.patterns import PATTERN_SYNTAX_HELP_TEXT


class TaxRuleForm(forms.ModelForm):
    class Meta:
        model = TaxRule
        fields = [
            "tax_classes",
            "customer_tax_groups",
            "country_codes_pattern",
            "region_codes_pattern",
            "postal_codes_pattern",
            "priority",
            "override_group",
            "tax",
            "enabled",
        ]
        help_texts = {
            "country_codes_pattern": string_concat(
                PATTERN_SYNTAX_HELP_TEXT,
                " ",
                _("Use ISO 3166-1 country codes (US, FI etc.)")
            ),
            "region_codes_pattern": string_concat(
                PATTERN_SYNTAX_HELP_TEXT,
                " ",
                _("Use two letter state codes for the US")
            ),
            "postal_codes_pattern": PATTERN_SYNTAX_HELP_TEXT,
        }

    def clean(self):
        data = super(TaxRuleForm, self).clean()
        data["country_codes_pattern"] = data["country_codes_pattern"].upper()
        return data


class TaxRuleEditView(CreateOrUpdateView):
    model = TaxRule
    template_name = "shuup/default_tax/admin/edit.jinja"
    form_class = TaxRuleForm
    context_object_name = "tax_rule"
    add_form_errors_as_messages = True


class TaxRuleListView(PicotableListView):
    model = TaxRule

    columns = [
        Column("id", _("Tax Rule")),
        Column("tax", _("Tax")),
        Column("tax_classes", _("Tax Classes")),
        Column("customer_tax_groups", _("Customer Tax Groups")),
        Column("country_codes_pattern", _("Countries")),
        Column("region_codes_pattern", _("Regions")),
        Column("postal_codes_pattern", _("Postal Codes")),
        Column("priority", _(u"Priority")),
        Column("override_group", _(u"Override Group")),
        Column("enabled", _(u"Enabled")),
    ]<commit_msg>Modify default tax for dynamic columns<commit_after># This file is part of Shuup.
#
# 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 import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import string_concat

from shuup.admin.utils.picotable import Column
from shuup.admin.utils.views import CreateOrUpdateView, PicotableListView
from shuup.default_tax.models import TaxRule
from shuup.utils.patterns import PATTERN_SYNTAX_HELP_TEXT


class TaxRuleForm(forms.ModelForm):
    class Meta:
        model = TaxRule
        fields = [
            "tax_classes",
            "customer_tax_groups",
            "country_codes_pattern",
            "region_codes_pattern",
            "postal_codes_pattern",
            "priority",
            "override_group",
            "tax",
            "enabled",
        ]
        help_texts = {
            "country_codes_pattern": string_concat(
                PATTERN_SYNTAX_HELP_TEXT,
                " ",
                _("Use ISO 3166-1 country codes (US, FI etc.)")
            ),
            "region_codes_pattern": string_concat(
                PATTERN_SYNTAX_HELP_TEXT,
                " ",
                _("Use two letter state codes for the US")
            ),
            "postal_codes_pattern": PATTERN_SYNTAX_HELP_TEXT,
        }

    def clean(self):
        data = super(TaxRuleForm, self).clean()
        data["country_codes_pattern"] = data["country_codes_pattern"].upper()
        return data


class TaxRuleEditView(CreateOrUpdateView):
    model = TaxRule
    template_name = "shuup/default_tax/admin/edit.jinja"
    form_class = TaxRuleForm
    context_object_name = "tax_rule"
    add_form_errors_as_messages = True


class TaxRuleListView(PicotableListView):
    url_identifier = "default_tax.tax_rule"
    model = TaxRule

    default_columns = [
        Column("id", _("Tax Rule")),
        Column("tax", _("Tax")),
        Column("tax_classes", _("Tax Classes")),
        Column("customer_tax_groups", _("Customer Tax Groups")),
        Column("country_codes_pattern", _("Countries")),
        Column("region_codes_pattern", _("Regions")),
        Column("postal_codes_pattern", _("Postal Codes")),
        Column("priority", _(u"Priority")),
        Column("override_group", _(u"Override Group")),
        Column("enabled", _(u"Enabled")),
    ]
{'fraction_non_alphanumeric': 0.10153294843718894, 'fraction_numerical': 0.005574357953414294, 'mean_word_length': 2.6618075801749272, 'pattern_counts': {'":': 6, '<': 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': '3002626', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1438, 'n_words': 335}