<s> from django . db . models . signals import post_save , pre_delete , m2m_changed <EOL> from django . db import models <EOL> from django . contrib import admin <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from sellmo import params <EOL> from sellmo . core import indexing <EOL> from sellmo . apps . pricing import Price <EOL> from sellmo . apps . customer . constants import ADDRESS_TYPES <EOL> from sellmo . utils . text import underscore_concat <EOL> from sellmo . contrib . settings import settings_manager <EOL> from sellmo . contrib . settings . signals import setting_changed <EOL> from . models import Tax , TaxRule , ProductTaxClass <EOL> from . constants import ( <EOL> TAX , DISPLAY_PRICES_INCLUDING_TAX , DISPLAY_PRICES_EXCLUDING_TAX , <EOL> DISPLAY_PRICES_INCLUDING_EXCLUDING_TAX , POLICY_CUSTOMER_ADDRESS <EOL> ) <EOL> group = _ ( "<STR_LIT>" ) <EOL> POLICY_CHOICES = tuple ( <EOL> ( <EOL> underscore_concat ( POLICY_CUSTOMER_ADDRESS , address_type ) , <EOL> _ ( "<STR_LIT>" ) % address_type <EOL> ) for address_type in ADDRESS_TYPES <EOL> ) <EOL> POLICY_DEFAULT = POLICY_CHOICES [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] if POLICY_CHOICES else None <EOL> settings_manager . add_setting ( <EOL> '<STR_LIT>' , <EOL> models . CharField ( <EOL> max_length = <NUM_LIT> , <EOL> null = POLICY_DEFAULT is None , <EOL> blank = POLICY_DEFAULT is None , <EOL> default = POLICY_DEFAULT , <EOL> choices = POLICY_CHOICES , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> group <EOL> ) <EOL> settings_manager . add_setting ( <EOL> '<STR_LIT>' , <EOL> models . BooleanField ( <EOL> default = False , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> group <EOL> ) <EOL> settings_manager . add_setting ( <EOL> '<STR_LIT>' , <EOL> models . BooleanField ( <EOL> default = False , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> group <EOL> ) <EOL> DISPLAY_PRICES_CHOICES = ( <EOL> ( DISPLAY_PRICES_INCLUDING_TAX , _ ( "<STR_LIT>" ) ) , <EOL> ( DISPLAY_PRICES_EXCLUDING_TAX , _ ( "<STR_LIT>" ) ) , <EOL> ( DISPLAY_PRICES_INCLUDING_EXCLUDING_TAX , _ ( "<STR_LIT>" ) ) , <EOL> ) <EOL> settings_manager . add_setting ( <EOL> '<STR_LIT>' , <EOL> models . CharField ( <EOL> max_length = <NUM_LIT:30> , <EOL> default = DISPLAY_PRICES_INCLUDING_TAX , <EOL> choices = DISPLAY_PRICES_CHOICES , <EOL> verbose_name = _ ( "<STR_LIT>" ) , <EOL> ) , <EOL> group <EOL> ) <EOL> def on_setting_changed ( sender , setting , old , new , site , ** kwargs ) : <EOL> if setting in ( '<STR_LIT>' , ) : <EOL> index = indexing . indexer . get_index ( '<STR_LIT>' ) <EOL> index . sync ( ) <EOL> setting_changed . connect ( on_setting_changed ) <EOL> def on_tax_class_m2m_changed ( sender , instance , action , reverse , ** kwargs ) : <EOL> if params . loaddata : <EOL> return <EOL> if action in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if not reverse : <EOL> _update_indexes ( tax_class = instance ) <EOL> else : <EOL> index = indexing . indexer . get_index ( '<STR_LIT>' ) <EOL> index . sync ( [ instance . pk ] ) <EOL> def on_tax_class_pre_delete ( sender , instance , ** kwargs ) : <EOL> _update_indexes ( tax_class = instance ) <EOL> def on_tax_class_post_save ( sender , instance , raw = False , ** kwargs ) : <EOL> if raw : <EOL> return <EOL> _update_indexes ( tax_class = instance ) <EOL> def on_tax_rule_m2m_changed ( sender , instance , action , reverse , ** kwargs ) : <EOL> if params . loaddata : <EOL> return <EOL> if action . startswith ( '<STR_LIT>' ) : <EOL> _update_indexes ( tax_rule = instance ) <EOL> def on_tax_rule_pre_delete ( sender , instance , ** kwargs ) : <EOL> _update_indexes ( tax_rule = instance ) <EOL> def on_tax_rule_post_save ( sender , instance , raw = False , ** kwargs ) : <EOL> if raw : <EOL> return <EOL> _update_indexes ( tax_rule = instance ) <EOL> def on_tax_pre_delete ( sender , instance , ** kwargs ) : <EOL> _update_indexes ( tax = instance ) <EOL> def on_tax_post_save ( sender , instance , raw = False , ** kwargs ) : <EOL> if raw : <EOL> return <EOL> _update_indexes ( tax = instance ) <EOL> def _update_indexes ( tax_class = None , tax_rule = None , tax = None ) : <EOL> products = None <EOL> index = indexing . indexer . get_index ( '<STR_LIT>' ) <EOL> index . sync ( products ) <EOL> for relation in ProductTaxClass . M2M_INVALIDATIONS : <EOL> field = getattr ( ProductTaxClass , relation ) <EOL> m2m_changed . connect ( on_tax_class_m2m_changed , sender = field . through ) <EOL> post_save . connect ( on_tax_class_post_save , sender = ProductTaxClass ) <EOL> pre_delete . connect ( on_tax_class_pre_delete , sender = ProductTaxClass ) <EOL> m2m_changed . connect ( on_tax_rule_m2m_changed , <EOL> sender = TaxRule . product_classes . through ) <EOL> m2m_changed . connect ( on_tax_rule_m2m_changed , <EOL> sender = TaxRule . customer_groups . through ) <EOL> m2m_changed . connect ( on_tax_rule_m2m_changed , sender = TaxRule . taxes . through ) <EOL> post_save . connect ( on_tax_rule_post_save , sender = TaxRule ) <EOL> pre_delete . connect ( on_tax_rule_pre_delete , sender = TaxRule ) <EOL> for subtype in Tax . SUBTYPES : <EOL> post_save . connect ( on_tax_post_save , sender = subtype ) <EOL> pre_delete . connect ( on_tax_pre_delete , sender = subtype ) </s>
